需求
0时区转为 +8 时区
入参:字符串 "2022-05-23 07:21:37"
代码
/* * 0时区转+8时区 */ func Transform0TimezoneTo8Timezone(timeStr string) string { var timeLayoutStr = "2006-01-02 15:04:05" t, err := time.ParseInLocation(timeLayoutStr, timeStr, time.Local) if err != nil { return timeStr } return t.Add(time.Hour * +8).Format(timeLayoutStr) }
- 测试
func TestTransform0TimezoneTo8Timezone(t *testing.T) { timeStr := "2022-05-23 07:21:37" RsTimestamp := Transform0TimezoneTo8Timezone(timeStr) fmt.Println(RsTimestamp) }