-
-
Save ttys3/94d0f7284ed280c983052d395a920b26 to your computer and use it in GitHub Desktop.
golang ambiguous year week number
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" | |
) | |
func main() { | |
mysqlFmt := "2006-01-02 15:04:05" | |
ambiguous, err := time.Parse(mysqlFmt, "2021-01-01 13:01:02") | |
if err != nil { | |
panic(err) | |
} | |
year, wk_num := ambiguous.ISOWeek() | |
fmt.Printf("time: %s year: %d wk_num: %d\n", ambiguous, year, wk_num) | |
// output: | |
// time: 2021-01-01 13:01:02 +0000 UTC year: 2020 wk_num: 53 | |
// but mysql think it is 2021 week 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment