Open In App

time.Month.String() Function in Golang With Examples

Improve
Improve
Like Article
Like
Save
Share
Report

In Go language, time packages supplies functionality for determining as well as viewing time. The Month.String() function in Go language is used to find the English name of the month. Moreover, this function is defined under the time package. Here, you need to import the “time” package in order to use these functions.

Syntax:

func (m Month) String() string

Here, “m” is the type Month.

Return Value: It returns a string which is the English name of the month.

Example 1:




// Golang program to illustrate the usage of
// (Month) String() function
  
// Including main package
package main
  
// Importing fmt and time
import "fmt"
import "time"
  
// Calling main
func main() {
  
    // Calling time.Month
    // with its parameter
    // of type int
    var m = time.Month(2)
  
    // Prints the English 
    // name of the month
    fmt.Println(m.String())
}


Output:

February

Example 2:




// Golang program to illustrate the usage of
// (Month) String() function
  
// Including main package
package main
  
// Importing fmt and time
import "fmt"
import "time"
  
// Calling main
func main() {
  
    // Calling time.Month
    // with its parameter
    // of type int
    var m = time.Month(12)
  
    // Prints the English name of 
    // the month
    fmt.Println(m.String())
}


Output:

December


Last Updated : 21 Apr, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads