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
+5.8k Linux : Disable and enable IPv4 forwarding
+11.7k Golang : How to detect a server/machine network interface capabilities?
+23.7k Find and replace a character in a string in Go
+24.1k Golang : Upload to S3 with official aws-sdk-go package
+5.4k Python : Delay with time.sleep() function example
+16.5k Golang : Merge video(OpenCV) and audio(PortAudio) into a mp4 file
+33.6k Golang : How to check if slice or array is empty?
+22.7k Golang : Round float to precision example
+15.2k JavaScript/JQuery : Detect or intercept enter key pressed example
+21.7k Golang : Setting up/configure AWS credentials with official aws-sdk-go
+23.2k Golang : Print out struct values in string format
+8.5k Android Studio : Import third-party library or package into Gradle Scripts