Skip to content

Instantly share code, notes, and snippets.

@ttys3
Forked from icasimpan/today_isoweek.go
Last active January 4, 2021 03:37
Show Gist options
  • Save ttys3/94d0f7284ed280c983052d395a920b26 to your computer and use it in GitHub Desktop.
Save ttys3/94d0f7284ed280c983052d395a920b26 to your computer and use it in GitHub Desktop.
golang ambiguous year week number
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