本文摘自网络,作者,侵删。
标准时间格式字符串转为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
本文来自:51CTO博客
感谢作者:1350368559
查看原文:go时间解析
相关阅读 >>
使用 mix/vega + mix/db 进行现代化的原生 php 开发
【Golang语言社区投稿】Golang高并发基于协程,通道的任务池
更多相关阅读请进入《Go》频道 >>

Go语言101
一个与时俱进的Go编程知识库。