epoch

epoch

原文:https://gobyexample.com/epoch

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
package main

import (
	"fmt"
	"time"
)

func main() {

	now := time.Now()
	fmt.Println(now) // 2023-08-10 16:46:30.7978556 +0800 CST m=+0.005433901

	fmt.Println(now.Unix())      // 1691657190
	fmt.Println(now.UnixMilli()) // 1691657190797
	fmt.Println(now.UnixNano())  // 1691657190797855600

	fmt.Println(time.Unix(now.Unix(), 0))     // 2023-08-10 16:46:30 +0800 CST
	fmt.Println(time.Unix(0, now.UnixNano())) // 2023-08-10 16:46:30.7978556 +0800 CST
}
最后修改 March 10, 2024: 更新 (ddf4687)