GO 获取时间的年份、月份以及日期

  1. 通过time获取年、月、日
year:=time.Now().Year()
month:=time.Now().Month()//time.Now().Month().String()
day:=time.Now().Day()
  1. 字符串转Time
tm := "2019-01-01 01:01:01"
t1, _ = time.Parse("2006-01-02 15:04:05", tm )

date := "2019-01-01"
t2, _ = time.Parse("2006-01-02", date)
  1. 毫秒时间戳转Time
ms:= 1572958141000
t := time.Unix(ms/1000, 0)
0%