Skip to content

Commit

Permalink
set timezone
Browse files Browse the repository at this point in the history
  • Loading branch information
wuhan005 committed Oct 12, 2023
1 parent 398038b commit a067eb5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
7 changes: 6 additions & 1 deletion helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ func getFormatTag(tagFormat string) []string {

t := tagFormat

now := time.Now()
location, _ := time.LoadLocation("Asia/Shanghai")
if location == nil {
location = time.FixedZone("Asia/Shanghai", 8*60*60)
}

now := time.Now().In(location)
t = strings.NewReplacer(
"%TIMESTAMP%", strconv.Itoa(int(now.Unix())), // %TIMESTAMP% Timestamp
"%YYYY%", strconv.Itoa(now.Year()), // %YYYY% Year
Expand Down

0 comments on commit a067eb5

Please sign in to comment.