dtxs9017 2019-07-30 21:57
浏览 110

我正在寻找一种可以将字符串格式化为ISO 8601时间戳的方法

I am trying to take a string and convert that string into ISO8601 timestamp format using Go.

I read a few StackOverflow posts and tried them, none of them worked for me. I might be doing it wrong?

My datetime string is something like

date := "8/16/2019 8:01:35 PM"
func main() {
    date := "8/16/2019 8:01:35 PM"
    t, _ := time.Parse("6/16/2019 3:07:53 PM", date)
    fmt.Println(t) // getting 0001-01-01 00:00:00 +0000 UTC
}

I am expecting to get a parsed DateTime value which is something like 2019-8-16T20:01:35 from the above code and then convert it to ISO8601 format, like 2019-8-16T20:01:35.000Z as an end result.

  • 写回答

1条回答 默认 最新

  • douhu4692 2019-07-30 22:33
    关注

    the numbers on the example date can only be as follows

    month: 1, 01, jan, January
    day: 2, 02
    year: 06, 2006,
    hour: 3, 03, or for 24hour 15,
    minutes: 4, 04
    seconds 5, 05, 05.000, 05.000000
    timezone -0700, MST

    input := "8/16/2019 8:01:35 PM"
    layout := "1/02/2006 3:04:05 PM"
    t, err := time.Parse(layout, input)
    fmt.Println(t, err)
    fmt.Println(t.Format("1/02/2006 3:04:05 PM")) // 31-Aug-2017
    

    go playground

    for more details checkout

    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置