[英]Convert CST DateTime to Unix timestamp in Golang
I have a datetime format 0000-00-00 00:00:00 in China Standard Time, I want to convert it to unix timestamp in Golang.我在中国标准时间有一个日期时间格式 0000-00-00 00:00:00,我想将其转换为 Golang 中的 unix 时间戳。
I am not sure what default timestamp we need, if we call time.Unix( ) directly.如果我们直接调用 time.Unix( ),我不确定我们需要什么默认时间戳。
just use time.Location只需使用时间。位置
func main() {
now := "2022-08-11 11:40:00"
location, err := time.LoadLocation("Asia/Shanghai")
if err != nil {
log.Fatalln(err)
}
t, err := time.ParseInLocation("2006-01-02 15:04:05", now, location)
if err != nil {
log.Fatalln(err)
}
//2022-08-11 11:40:00 +0800 CST
fmt.Println(t)
//1660189200
fmt.Println(t.Unix())
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.