diff --git a/time.go b/time.go index 0510648..5358ac9 100644 --- a/time.go +++ b/time.go @@ -7,16 +7,16 @@ var GMT8 = time.FixedZone("CST", 8*3600) // TimeToStr 时间戳格式化为时间字符串 // 若 timestamp < 0,则使用 `time.Now()` -func TimeToStr(layout string, timestamp int64) string { +func TimeToStr(layout string, timestamp int64, loc *time.Location) string { if timestamp < 0 { return time.Now().In(time.Local).Format(layout) } - return time.Unix(timestamp, 0).In(time.Local).Format(layout) + return time.Unix(timestamp, 0).In(loc).Format(layout) } // StrToTime 时间字符串解析为时间戳 -func StrToTime(layout, datetime string) time.Time { - t, _ := time.ParseInLocation(layout, datetime, time.Local) +func StrToTime(layout, datetime string, loc *time.Location) time.Time { + t, _ := time.ParseInLocation(layout, datetime, loc) return t }