I'd like to write a method that will populate a Go Language array with the common timezones that are accepted by the time.Format()
call, for use in an HTML template (Form select to allow them to read and choose their timezone). Is there a common way to do this?
获取Go中有效时区的列表
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
2条回答 默认 最新
- dthtvk3666 2016-10-19 12:01关注
To get a list of time zones, you can use something like:
package main import ( "fmt" "io/ioutil" "strings" ) var zoneDirs = []string{ // Update path according to your OS "/usr/share/zoneinfo/", "/usr/share/lib/zoneinfo/", "/usr/lib/locale/TZ/", } var zoneDir string func main() { for _, zoneDir = range zoneDirs { ReadFile("") } } func ReadFile(path string) { files, _ := ioutil.ReadDir(zoneDir + path) for _, f := range files { if f.Name() != strings.ToUpper(f.Name()[:1]) + f.Name()[1:] { continue } if f.IsDir() { ReadFile(path + "/" + f.Name()) } else { fmt.Println((path + "/" + f.Name())[1:]) } } }
output:
Africa/Abidjan Africa/Accra Africa/Addis_Ababa Africa/Algiers Africa/Asmara Africa/Asmera Africa/Bamako Africa/Bangui ...
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 微信小程序协议怎么写
- ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
- ¥20 怎么用dlib库的算法识别小麦病虫害
- ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
- ¥15 java写代码遇到问题,求帮助
- ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
- ¥15 有了解d3和topogram.js库的吗?有偿请教
- ¥100 任意维数的K均值聚类
- ¥15 stamps做sbas-insar,时序沉降图怎么画
- ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看