September 2017
Intermediate to advanced
466 pages
9h 33m
English
This section will present a small Go program named dateTime.go that shows how to work with times and dates in Go. The code of dateTime.go will be presented in three parts. The first part is the following:
package main
import (
"fmt"
"time"
)
func main() {
fmt.Println("Epoch time:", time.Now().Unix())
t := time.Now()
fmt.Println(t, t.Format(time.RFC3339))
fmt.Println(t.Weekday(), t.Day(), t.Month(), t.Year())
time.Sleep(time.Second)
t1 := time.Now()
fmt.Println("Time difference:", t1.Sub(t))
formatT := t.Format("01 January 2006")
fmt.Println(formatT)
loc, _ := time.LoadLocation("Europe/London")
londonTime := t.In(loc)
fmt.Println("London:", londonTime)
In this part, you can see how you can change a date from one ...
Read now
Unlock full access