golang 时间转换

时间的类型   date    time   timestamp

data        2019-3-20 [15:04:05]

time         2019-3-20 +0.23123 CST

timestamp    1553069264

t := time.Now()  //  获取当前时间

layout = "2006-01-02 [15:04:05]" //  date格式12150405

loc := time.LoadLocation("Location") //获取当前时区

(1) time =>

t.Format(layout)     //time => date

t.Unix()                 // time => timestamp

(2)timestamp => time

time.Unix(timestamp,0) //

(3)date  => time

time.ParseInLocation(layout,date,loc)

你可能感兴趣的:(golang 时间转换)