在Go中, 我们可以以秒, 毫秒, 纳秒为单位生成时间。时间包具有所需的方法, 如秒, 纳米等, 可以为我们提供帮助。
参考时间是Unix纪元。我们还可以将纳秒或毫秒转换为时间格式。
package main
import "fmt"
import "time"
func main() {
p := fmt.Println
current_time := time.Now()
secs := current_time.Unix()
nanos := current_time.UnixNano()
fmt.Println(current_time)
millis := nanos / 1000000
p(secs)
p(millis)
p(nanos)
p(time.Unix(secs, 0))
p(time.Unix(0, nanos))
}
输出:
2017-10-06 17:34:13.971527666 +0530 IST m=+0.000334769
1507291453
1507291453971
1507291453971527666
2017-10-06 17:34:13 +0530 IST
2017-10-06 17:34:13.971527666 +0530 IST
微信公众号
手机浏览(小程序)
Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(): Failed to enable crypto in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_50014.jpg): failed to open stream: operation failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57