日期格式化时区
time := time.Now()
loc, err := time.LoadLocation("") // 默认UTC
loc, err := time.LoadLocation("Local") // 一般为CST
loc, err := time.LoadLocation("America/Los_Angeles") // 美国洛杉矶PDT
loc, _:= time.LoadLocation("Asia/Chongqing") // CST
获取当前时间并格式化
// 格式化
// golang中格式不是‘yyyy-MM-dd HH:mm:ss’,而是采用golang诞生时间作为格式
t = "2006-01-02 15:04:05"
time := time.Now()
fmt.Println(time.Format(t))
格式化后的日期字符串转回Time
// 格式化
t = "2006-01-02 15:04:05"
// 日期字符串
str = "2017-09-13 00:00:01"
loc, err := time.LoadLocation("Local")
time, err := time.ParseInLocation(t, str, loc)
fmt.Println(time)
if err == Nil{
}
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。