将秒数转换为Golang中的时钟时间。

huangapple go评论69阅读模式
英文:

Parse time seconds to clock in Golang

问题

如何在Golang中将时间秒解析为时钟格式?

例如:

输入:0      => 输出:'12:00 AM'
输入:60     => 输出:'12:01 AM'
输入:60*60  => 输出:'1:00 AM'
英文:

How to parse time seconds to the clock format in Golang?

For example:

input: 0      => output: '12:00 AM'
input: 60     => output: '12:01 AM'
input: 60*60  => output: '1:00 AM'

答案1

得分: 5

将秒数放入time.Date函数中:

t := time.Date(0, 0, 0, 0, 0, sec, 0, time.UTC)
fmt.Println(t.Format("03:04 PM"))

https://play.golang.org/p/zV720y4E-o

英文:

Put the number of seconds into the time.Date function:

t := time.Date(0, 0, 0, 0, 0, sec, 0, time.UTC)
fmt.Println(t.Format("03:04 PM"))

https://play.golang.org/p/zV720y4E-o

huangapple
  • 本文由 发表于 2016年10月5日 05:16:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/39861898.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定