go时间解析


本文摘自网络,作者,侵删。

标准时间格式字符串转为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/132070
last 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.go
const (<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时间解析

相关阅读 >>

Golang出现panic是什么原因

02 - 【Go语言学习笔记】变量和常量

Go - 变量声明

2020.3.30日结

[系列] - Go-gin-api 路由中间件 - 签名验证(七)

Golang常用的http请求操作

Golang 笔记之深入浮点数

Golang核心编程

Golang gmssl编译不过

Go语言标准库之log

更多相关阅读请进入《Go》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...