时间和日期类型
1.time包
2.time.Time类型,用来表示时间
3.获取当前时间,now :=time.Now()
4.日期函数
time.Now().Day()=>日期
time.Now().Minute()=>分钟
time.Now().Month()=>月份
time.Now().Year()=>年份
5.time.Duration纳秒
6.常规常量
const (
Nanosecond Duration = 1
Microsecond = 1000 * Nanosecond
Millisecond = 1000 * Microsecond
Second = 1000 * Millisecond
Minute = 60 * Second
Hour = 60 * Minute
)
7.格式化 2006/1/02 15:04时间原点
now := time.Now()
fmt.Println(now.Format("02/1/2006 15:04"))
fmt.Println(now.Format("2006/1/02 15:04"))
fmt.Println(now.Format("2006/1/02"))
8.初始化一个指定日期
time1 := time.Date(2017,11,11,0,0,0,0,time.Local)
fmt.Println(time1.Format("2006-01-02 15:04"))