首页 > 其他分享 >golang获取0点时间戳

golang获取0点时间戳

时间:2022-10-25 22:58:56浏览次数:75  
标签:Now 秒数 nowTime golang 获取 时间 now

1.获取当地时间0点时间戳
func GetZeroTime() int64 {
    nowTime := time.Now()
    now := nowTime.Unix()
    _, offsetSeconds := nowTime.Zone()          //相对于utc时区偏移秒数
    sec := (now + int64(offsetSeconds)) % 86400 //相对于当前时区0点偏移秒数
    return now - sec
}

2.时间格式化
refer: https://www.muzhuangnet.com/show/20791.html
golang 的时间格式串Layout固定为 2006-01-02 15:04:05
time.Now.Format("20060102150405")
time.Now.Format("2006-01-02 15:04:05")

标签:Now,秒数,nowTime,golang,获取,时间,now
From: https://www.cnblogs.com/ginkgo-leaf/p/16826684.html

相关文章