ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
获取当前时间,依次打印年月日。 ~~~ func getNow() { now := time.Now() fmt.Println(now) year := now.Year() month := now.Month() day := now.Day() hour := now.Hour() minute := now.Minute() second := now.Second() fmt.Println(year, int(month), day, hour, minute, second) } func main() { getNow() } // 输出: 2022-06-09 15:04:36.5725912 +0800 CST m=+0.003092201 2022 6 9 15 4 36 ~~~ 时间戳 ~~~go // timestamp 时间戳 func getTimestamp() { now := time.Now() // 获取当前时间 timestamp := now.Unix() // 秒级时间戳 milli := now.UnixMilli() // 毫秒时间戳 Go1.17+ micro := now.UnixMicro() // 微秒时间戳 Go1.17+ nano := now.UnixNano() // 纳秒时间戳 fmt.Println(timestamp, milli, micro, nano) } // 输出: 1654758994 1654758994831 1654758994831770 1654758994831770100 ~~~