【问题标题】:Parse time seconds to clock in Golang解析时间秒以在 Golang 中打卡
【发布时间】:2016-10-04 21:16:47
【问题描述】:

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

例如:

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

【问题讨论】:

    标签: go


    【解决方案1】:

    将秒数放入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

    【讨论】:

      猜你喜欢
      • 2015-03-23
      • 1970-01-01
      • 2016-10-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-15
      相关资源
      最近更新 更多