feat: refact timezone calling

This commit is contained in:
engigu
2026-02-09 18:39:41 +08:00
parent eb05eafb72
commit f693c32554
10 changed files with 64 additions and 18 deletions
+31
View File
@@ -0,0 +1,31 @@
package systime
import "time"
// CST 东八区时区
var CST = time.FixedZone("CST", 8*3600)
// Now 返回东八区的当前时间
func Now() time.Time {
return time.Now().In(CST)
}
// InCST 将给定时间转换为东八区时间
func InCST(t time.Time) time.Time {
return t.In(CST)
}
// FormatTime 将时间格式化为标准格式
func FormatTime(t time.Time) string {
return InCST(t).Format("2006-01-02 15:04:05")
}
// FormatDate 将时间格式化为日期格式
func FormatDate(t time.Time) string {
return InCST(t).Format("2006-01-02")
}
// FormatDatetime 用于备份等文件命名格式
func FormatDatetime(t time.Time) string {
return InCST(t).Format("20060102_150405")
}