Go: Day of week

The Weekday function returns returns the day of the week of a time.Time.

func (t Time) Weekday() Weekday

In use:

weekday := time.Now().Weekday()
fmt.Println(weekday)      // "Tuesday"
fmt.Println(int(weekday)) // "2"

Type Weekday

The time.Weekday type specifies a day of the week (Sunday = 0, …).

type Weekday int

const (
        Sunday Weekday = iota
        Monday
        Tuesday
        Wednesday
        Thursday
        Friday
        Saturday
)

Comments

Be the first to comment!