Skip to content

Commit 9aa0067

Browse files
committed
perf(时区): 默认设置为中国时区
1 parent e2cecae commit 9aa0067

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/xinliangnote/go-gin-api/pkg/env"
1212
"github.com/xinliangnote/go-gin-api/pkg/logger"
1313
"github.com/xinliangnote/go-gin-api/pkg/shutdown"
14+
"github.com/xinliangnote/go-gin-api/pkg/time_parse"
1415

1516
"go.uber.org/zap"
1617
)
@@ -33,7 +34,7 @@ func main() {
3334
accessLogger, err := logger.NewJSONLogger(
3435
logger.WithDisableConsole(),
3536
logger.WithField("domain", fmt.Sprintf("%s[%s]", configs.ProjectName, env.Active().Value())),
36-
logger.WithTimeLayout("2006-01-02 15:04:05"),
37+
logger.WithTimeLayout(time_parse.CSTLayout),
3738
logger.WithFileP(configs.ProjectAccessLogFile),
3839
)
3940
if err != nil {
@@ -44,7 +45,7 @@ func main() {
4445
cronLogger, err := logger.NewJSONLogger(
4546
logger.WithDisableConsole(),
4647
logger.WithField("domain", fmt.Sprintf("%s[%s]", configs.ProjectName, env.Active().Value())),
47-
logger.WithTimeLayout("2006-01-02 15:04:05"),
48+
logger.WithTimeLayout(time_parse.CSTLayout),
4849
logger.WithFileP(configs.ProjectCronLogFile),
4950
)
5051

pkg/time_parse/time_parse.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ func init() {
1818
if cst, err = time.LoadLocation("Asia/Shanghai"); err != nil {
1919
panic(err)
2020
}
21+
22+
// 默认设置为中国时区
23+
time.Local = cst
2124
}
2225

2326
// RFC3339ToCSTLayout convert rfc3339 value to china standard time layout

0 commit comments

Comments
 (0)