package time
time包提供了时间的显示和测量用的函数。日历的计算采用的是公历。)
time.now()
1、Now返回当前本地时间。
func Now() Time
代码演示:
// 返回当前本地时间
now := time.Now()
fmt.Printf("now = %v\n", now) // 输出本地时间
fmt.Printf("now type = %T\n", now) // 输出now类型
输出:
now = 2020-11-29 16:04:17.130252 +0800 CST m=+0.003998901
now type = time.Time
2、通过now获取年月日时分秒
代码演示:
// 通过now获取年月日时分秒
fmt.Printf("年:%v\n", now.Year()) // 获取 年
fmt.Printf("月:%v\n"