5

How to get current timestamp

 3 years ago
source link: https://yourbasic.org/golang/current-time/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

How to get current timestamp

yourbasic.org/golang
wrist-watch-and-dog.jpg

Use time.Now and one of time.Unix or time.UnixNano to get a timestamp.

now := time.Now()      // current local time
sec := now.Unix()      // number of seconds since January 1, 1970 UTC
nsec := now.UnixNano() // number of nanoseconds since January 1, 1970 UTC

fmt.Println(now)  // time.Time
fmt.Println(sec)  // int64
fmt.Println(nsec) // int64
2009-11-10 23:00:00 +0000 UTC m=+0.000000000
1257894000
1257894000000000000

Share:             


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK