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
+15.9k Golang : How to make a file read only and set it to writable again?
+7.4k Golang : Another camera capture GUI application with GTK and OpenCV
+6k Web : How to see your website from different countries?
+12.6k Android Studio : Use image as AlertDialog title with custom layout example
+16k Golang : Qt image viewer example
+8.7k Golang : Test a slice of integers for odd and even numbers
+6.8k Golang Hello World Example
+8k Golang : Play .WAV file from command line
+5.5k Golang : Skip or discard items of non-interest when iterating example
+12.2k Golang : Set image canvas or background to transparent
+18.1k Golang : Example for DSA(Digital Signature Algorithm) package functions
+5.1k Javascript : Get operating system and browser information