Golang time.Time.ISOWeek() function example

package time

Golang time.Time.ISOWeek() function usage example. Use in calculating the week number in a given year.

 package main

 import (
 "fmt"
 "time"
 )

 func main() {

 now := time.Now()

 fmt.Println("Today : ", now.Format(time.ANSIC))

 year, week := now.ISOWeek()

 fmt.Printf("The ISO 8601 year is %d and week is %d \n", year, week)
 }

Sample output :

Today : Fri Aug 7 13:42:24 2015

The ISO 8601 year is 2015 and week is 32

Reference :

http://golang.org/pkg/time/#Time.ISOWeek

Advertisement