-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtime
35 lines (27 loc) · 922 Bytes
/
time
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package main
import (
"fmt"
"time"
)
func main() {
//golang默认就是local.time,如果特殊可以自定义时区
t := time.Now().Local().Format("2006-01-02 15:04:05")
fmt.Println(t)
//使用扩展
fmt.Println(time.Now())
// 输出: 2019-04-30 14:41:59.661602 +0800 CST m=+0.000225294
// 获取当前unix时间戳(秒)
fmt.Println(time.Now().Unix()) // 输出: 1556615702
// 获取当前unix时间戳(毫秒)
fmt.Println(time.Now().UnixNano() / 1e6) // 输出: 1556615702009
// 获取当前unix时间戳(纳秒)
fmt.Println(time.Now().UnixNano()) // 输出: 1556615702009257000
}
const (
Nanosecond Duration = 1
Microsecond = 1000 * Nanosecond //纳秒
Millisecond = 1000 * Microsecond //毫秒
Second = 1000 * Millisecond //秒
Minute = 60 * Second //分
Hour = 60 * Minute //小时
)