go--time包
阿新 • • 發佈:2018-08-16
bsp The 時間 location 小時 Go語言 模版 col charge
格式化字符串 轉 時間戳
////獲取本地location toBeCharge := "2015-01-01 00:00:00" //待轉化為時間戳的字符串 註意 這裏的小時和分鐘還要秒必須寫 因為是跟著模板走的 修改模板的話也可以不寫 timeLayout := "2006-01-02 15:04:05" //轉化所需模板 loc, _ := time.LoadLocation("asia/shanghai") //重要:獲取時區 theTime, _ := time.ParseInLocation(timeLayout, toBeCharge, loc) //使用模板在對應時區轉化為time.time類型sr := theTime.Unix() //轉化為時間戳 類型是int64 fmt.Println(theTime) //打印輸出theTime 2015-01-01 15:15:00 +0800 CST fmt.Println(sr)
時間戳 轉 格式化字符串
// 時間戳轉換成格式化字符串 timeLayout := "2006-01-02 15:04:05" // Go語言時間轉換的模版 t1 := time.Now().Unix() ss := time.Unix(t1,0).Format(timeLayout) fmt.Println(ss)
go--time包