I just want to take an integer input and convert it into corresponding month using Go time package. Is there a way apart from defining months in using a const block and using iota to incrementally represent them ?
I just want to take an integer input and convert it into corresponding month using Go time package. Is there a way apart from defining months in using a const block and using iota to incrementally represent them ?
收起
You can use the type time.Month
, which implements the Stringer
interface, which means you can do something like:
m := time.Month(10)
fmt.Println(m) //"October" - could also do m.String() here
fmt.Println(int(m)) //10
报告相同问题?