Q:

Golang program to print all months using predefined constants

belongs to collection: Golang Date & Time Programs

0

In this program, we will get the name of months using predefined constants and then print them on the console screen.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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 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.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Golang Date & Time Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
<< Golang program to print date and time according to...