golang获取0点时间戳

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

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")

posted @ 2022-10-25 22:44  小夜天  阅读(741)  评论(0编辑  收藏  举报