Created
July 25, 2024 17:24
-
-
Save crazyoptimist/ae988a41364c147b36bd261edca9734f to your computer and use it in GitHub Desktop.
Guide for using time zone in go.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"time" | |
_ "time/tzdata" // Embed the timezone database | |
) | |
func main() { | |
utcTime := time.Date(2024, time.Now().Month(), 26, 1, 30, 0, 0, time.UTC) | |
loc, err := time.LoadLocation("America/Los_Angeles") | |
if err != nil { | |
fmt.Println("error loading location: ", err) | |
return | |
} | |
localTime := utcTime.In(loc) | |
fmt.Println("UTC Day: ", utcTime.Day()) | |
fmt.Println("PDT Day: ", localTime.Day()) | |
fmt.Println("Are those two times the same?", utcTime.Equal(localTime)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment