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时间解析

相关阅读 >>

使用 mix/vega + mix/db 进行现代化的原生 php 开发

Golang mysql操作介绍

Golang互斥锁

Golang语言社区投稿】Golang高并发基于协程,通道的任务池

[Go-linq]-Go的.net linq式查询方法

Go 1.15 版本的优化清单【总结】

Go语言类型转换

Golang入门三:类型

Golang怎么判断slice是否为空

Golang依赖注入工具wire指南

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




打赏

取消

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

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

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

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

评论

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