3

How to find the day of week

 3 years ago
source link: https://yourbasic.org/golang/day-of-week-int/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

How to find the day of week

yourbasic.org/golang
calendar-card.jpg

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
)

Share:             


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK