Home »
Golang »
Golang Programs
Golang program to print all months using predefined constants
Here, we are going to learn how to print all months using predefined constants in Golang (Go Language)?
Submitted by Nidhi, on March 23, 2021 [Last updated : March 04, 2023]
Printing all months using predefined constants in Golang
Problem Solution:
In this program, we will get the name of months using predefined constants and then print them on the console screen.
Program/Source Code:
The source code to print all months using predefined constants is given below. The given program is compiled and executed successfully.
Golang code to print all months using predefined constants
// 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)
}
Output:
January
February
March
April
May
June
July
August
September
October
November
December
Explanation:
In the above program, we declare the package main. The main package is used to tell the Go language compiler that the package must be compiled and produced the executable file. Here, we imported the fmt and time packages to use time and fmt related functions.
In the main() function, we used predefined constants of time structure to get the name of months. After that, we printed the name of months on the console screen.
Golang Date & Time Programs »