标准时间格式字符串转为time类型
https://pkg.go.dev/time?utm_source=gopls#Parse
func time.Parse(layout string, value string) (time.Time, error)
其中layout的时间必须是"2006-01-02 15:04:05"这个时间
vmcoreTime="2021-04-07 07:45:22"
time, _ := time.Parse("2006-01-02 15:04:05", vmcoreTime)
fmt.Println(time)
fmt.Println(reflect.TypeOf(time))
输出:
time.Time
2021-04-07 07:45:22 +0000 UTC
把系统reboot的时间转为标准时间输出
https://developer.aliyun.com/article/132070last reboot -F -w -x -i | grep reboot
reboot system boot 0.0.0.0 Wed Apr 7 07:47:52 2021
https://golang.org/src/time/format.goconst (<br/>ANSIC = "Mon Jan _2 15:04:05 2006"<br/>)
https://pkg.go.dev/time?utm_source=gopls#ParseInLocation
func time.ParseInLocation(layout string, value string, loc *time.Location) (time.Time, error)
fmt.Println(rebootTime)
location, _ := time.LoadLocation("Asia/Shanghai")
time, _ := time.ParseInLocation(time.ANSIC, rebootTime, location)
fmt.Println(time)
Wed Apr 7 07:47:52 2021
2021-04-07 07:47:52 +0800 CST
有疑问加站长微信联系(非本文作者)