Skip to content

Commit

Permalink
perf(时区): 默认设置为中国时区
Browse files Browse the repository at this point in the history
  • Loading branch information
xinliangnote committed Nov 13, 2021
1 parent e2cecae commit 9aa0067
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 3 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/xinliangnote/go-gin-api/pkg/env"
"github.com/xinliangnote/go-gin-api/pkg/logger"
"github.com/xinliangnote/go-gin-api/pkg/shutdown"
"github.com/xinliangnote/go-gin-api/pkg/time_parse"

"go.uber.org/zap"
)
Expand All @@ -33,7 +34,7 @@ func main() {
accessLogger, err := logger.NewJSONLogger(
logger.WithDisableConsole(),
logger.WithField("domain", fmt.Sprintf("%s[%s]", configs.ProjectName, env.Active().Value())),
logger.WithTimeLayout("2006-01-02 15:04:05"),
logger.WithTimeLayout(time_parse.CSTLayout),
logger.WithFileP(configs.ProjectAccessLogFile),
)
if err != nil {
Expand All @@ -44,7 +45,7 @@ func main() {
cronLogger, err := logger.NewJSONLogger(
logger.WithDisableConsole(),
logger.WithField("domain", fmt.Sprintf("%s[%s]", configs.ProjectName, env.Active().Value())),
logger.WithTimeLayout("2006-01-02 15:04:05"),
logger.WithTimeLayout(time_parse.CSTLayout),
logger.WithFileP(configs.ProjectCronLogFile),
)

Expand Down
3 changes: 3 additions & 0 deletions pkg/time_parse/time_parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ func init() {
if cst, err = time.LoadLocation("Asia/Shanghai"); err != nil {
panic(err)
}

// 默认设置为中国时区
time.Local = cst
}

// RFC3339ToCSTLayout convert rfc3339 value to china standard time layout
Expand Down

0 comments on commit 9aa0067

Please sign in to comment.