Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Time example

  • time
  • Now
  • Unix

The Now function of the time package will return a representation of the current time. When printed it will show well formatted datetime string, but we can also use the Unix and UnixNano functions to the the time elapsed since the epoch in seconds and nanoseconds respectively.

package main

import (
	"fmt"
	"time"
)

func main() {
	t := time.Now()
	fmt.Printf("%T\n", t)
	fmt.Println(t)
	fmt.Println(t.Unix())
	fmt.Println(t.UnixNano())
}
time.Time
2020-04-24 21:54:38.111505742 +0300 IDT m=+0.000032815
1587754478
1587754478111505742