Skip to content
Home » How to print all months using predefined constants in Golang

How to print all months using predefined constants in Golang

Learn about How to print all months using predefined constants in Golang in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.

How to print all months using predefined constants in Golang

// Golang program to print all months
// using predefined constants

package main

import "fmt"
import "time"

func main() {
	fmt.Println(time.January)
	fmt.Println(time.February)
	fmt.Println(time.March)
	fmt.Println(time.April)
	fmt.Println(time.May)
	fmt.Println(time.June)
	fmt.Println(time.July)
	fmt.Println(time.August)
	fmt.Println(time.September)
	fmt.Println(time.October)
	fmt.Println(time.November)
	fmt.Println(time.December)
}

In the above program, we declare the package main. The main package instructs the Go language compiler that the package must be compiled and an executable file generated. We imported the fmt package, which contains the files of the fmt package, and then we can use a function related to the fmt package. Here, we used predefined constants of time structure to get the name of months

Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.

Similar Codes :
How to iterate map elements using the range in Golang
How to create a copy of the map in Golang