Here, We are going to learn about how to get current weekday in go and what function will be used to get the current weekday with program and example.
We will use Weekday() method of time package to get current weekday in go.
Function prototype:
func (t Time) Weekday() Weekday
Return type:
Weekday() method of time package returns the day of the week specified by given time i.e t.
Weekday: type Weekday int
const (
Sunday Weekday = iota
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
)
Example:
t := time.Now().Weekday()
Now t will have current weekday.
Program:
package main
import (
"fmt"
"time"
)
func main() {
week_day := time.Now().Weekday()
fmt.Println("Current Week day: ", week_day)
week_day_in_no := int(week_day)
fmt.Println("Current Week day as number: ", week_day_in_no)
}
Output:
Current Week day: Friday
Current Week day as number: 5
To learn more about golang, You can refer given below link:
https://techieindoor.com/go-lang-tutorial/
References:
https://golang.org/doc/ https://golang.org/pkg/