How to get current month in golang?
May 10, 2022Hi Friends 👋,
Welcome To aGuideHub! ❤️
Today, we are going to learn how to get the current month and print it in a golang console, here we will use the time
package to get a month.
Basically, we will use the time.Now()
method to get the current time, after that we use the Month()
method to get a current month.
So, let’s start coding…
package main
import (
"fmt"
"time"
)
func main() {
currentMonth := time.Now().Month();
fmt.Print(currentMonth)
}
When you run the above code you will get the current month in your golang console, let’s check the output.
All the best 👍