How to Get Current Weekday in Golang?

With the help of time.Now().Weekday() function, we can get the weekday in Golang by importing time module.

Syntax: time.Now().Weekday()
Return: Return current weekday.

Example #1: In this example, we can see that by using time.Now().Weekday() function, we are able to get the weekday.

filter_none

edit
close

play_arrow

link
brightness_4
code

// Golang program to get the current weekday
package main
  
// Here "fmt" is formatted IO which 
// is same as C’s printf and scanf.
import "fmt"
  
// importing time module
import "time"
  
// Main function
func main() {
  
    // Using time.Now().Weekday() function.
    dt := time.Now().Weekday()
    fmt.Println(dt.String())
}

chevron_right


Output:

Monday

Example #2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Golang program to get the current weekday
package main
  
// Here "fmt" is formatted IO which
// is same as C’s printf and scanf.
import "fmt"
  
// importing time module
import "time"
  
// Main function
func main() {
  
    // Using time.Now().Weekday() function
    dt := time.Now().Weekday()
    fmt.Println(int(dt))
  
}

chevron_right


Output:

1
My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.