我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

如何在Go中将数字转换为一个月

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

https://play.golang.org/p/PeFfVZZIK_

近期文章

  • goroutine和线程之间的区别
  • 使用/ rs / cors作为Buffalo固件的示例?
  • 导航到带有golang的字符串路径变量的地图
  • 在不知道具体类型的情况下解码gob输出
  • 如何使用Aerospike客户端进行触摸获取
  • 为什么goland 1.0 EAP提示“#command-line-arguments undefined:NewServer”
  • 如何在http请求中了解客户端域
  • 在Go中,如何将bson byte []数据解组为结构数组?
  • golang不能将type用作sort.Sort的参数类型
  • 如何检查结构的特定属性是否为空?
  • gorm golang one2many同一张桌子
  • 如何从数据存储区获取ID以更新实体?
  • 对字符串的简单mapReduce操作
  • 在Go中压缩来自阅读器的数据
  • Google数据存储中的唯一电子邮件
  • 如何从标准输入中按字节读取?
  • socket.go中SimpleQuery中的本地互斥锁
  • 以下Go数组操作起什么作用?
  • 执行命令时如何将文件用作stdin
  • 使用govaluate比较表达式中的日期值

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华