2.时间格式化 字符串格式化----结果字符串
// TPFunDateTimeStringFormat 时间格式化 字符串格式化----结果字符串
func TPFunDateTimeStringFormat(timeValue string, fmt string) string {
//timeValue := "2018-11-10T23:38:22.771406875+08:00" //时间字符串
timeLayout := "2006-01-02T15:04:05.999999999Z07:00" //所需模板
loc, _ := time.LoadLocation("Local") //***获取时区***
theTime, _ := time.ParseInLocation(timeLayout, timeValue, loc) //使用模板在对应时区转化为time.time类型
// 0001-01-01T00:00:00Z这里也表示时间为null
if theTime.IsZero() {
return ""
} else {
//时间戳转日期
//dataTimeStr := theTime.Format("2006-01-02 15:04:05") //使用模板格式化为日期字符串
dataTimeStr := theTime.Format(fmt) //使用模板格式化为日期字符串
return dataTimeStr
}
}