Golang time.Time.Weekday() function example
package time
Golang time.Time.Weekday() function usage example. Useful in situation where you want to calculate the weekday of a given date, such as if this year the day is Sunday, what is the weekday for next year.
package main
import (
"fmt"
"time"
)
func main() {
now := time.Now()
fmt.Println("Today : ", now.Format(time.ANSIC))
fmt.Println("Week day : ", now.Weekday().String())
nextYear := now.Add(365 * 24 * time.Hour)
fmt.Println("Next year : ", nextYear.Format(time.ANSIC))
fmt.Println("Next year day : ", nextYear.Weekday().String())
}
Sample output :
Today : Tue Aug 11 17:02:46 2015
Week day : Tuesday
Next year : Wed Aug 10 17:02:46 2016
Next year day : Wednesday
Reference :
Advertisement
Something interesting
Tutorials
+7.4k Golang : Fixing Gorilla mux http.FileServer() 404 problem
+8.2k Golang : Append and add item in slice
+7.2k Golang : Get environment variable
+10.1k Golang : Channels and buffered channels examples
+14k Golang : How to check if a file is hidden?
+23.5k Golang : Check if element exist in map
+15.2k Golang : How to add color to string?
+14.8k Golang : Send email with attachment(RFC2822) using Gmail API example
+23k Golang : Calculate time different
+10.2k Golang : Print how to use flag for your application example
+14k Golang : Human readable time elapsed format such as 5 days ago
+32.5k Golang : Math pow(the power of x^y) example