package main import ( "fmt" "time" ) func main() { now := time.Now() currentMonth := now.Month() fmt.Printf("The current month is %v\n", currentMonth) }
package main import ( "fmt" "time" ) func main() { now := time.Now() currentMonth := now.Month() someTime := time.Date(2021, time.May, 1, 0, 0, 0, 0, time.UTC) someMonth := someTime.Month() if currentMonth == someMonth { fmt.Println("The current month is May") } else { fmt.Println("The current month is not May") } }In this example, time.Date() is used to create a time.Time object representing May 1st, 2021. Then, the Month() method is called on both that object and the current time to get the corresponding month values. Finally, the two values are compared using the == operator to determine whether the current month is May or not. Both examples use the built-in time package.