Skip to content
Related Articles

Related Articles

How to Get Current Weekday in Golang?
  • Last Updated : 21 Apr, 2020

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.




// 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())
}

Output:

Monday

Example #2:




// 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))
  
}

Output:

1

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.




My Personal Notes arrow_drop_up
Recommended Articles
Page :