golang中使用parse将字符串格式化。但parse返回的是UTC的时间。当我将其转换成时间戳的时候快了8h,这不是我想要的结果。这需要使用func ParseInLocation(layout, value string, loc *Location) (Time, error)函数格式化成本地时区时间。package main
import (
"fmt"
"time"
)
func main() {
dateStr := "2015-12-14 00:00:00"
timestamp1, _ := time.Parse("2006-01-02 00:00:00", dateStr)
timestamp2, _ := time.ParseInLocation("2006-01-02 00:00:00", dateStr, time.Local)
fmt.Println(time.Local)
fmt.Println(timestamp1, timestamp2) //2015-12-14 00:00:00 +0000 UTC 2015-12-14 00:00:00 +0800 CST
fmt.Println(timestamp1.Unix(), timestamp2.Unix()) //1450051200 14
...
继续阅读
(48)