duancashi1362 2018-05-02 21:36
浏览 18
已采纳

如何在异常时间格式之间进行转换golang

I referenced this post: How to convert date format in golang? and have this code on the playground:

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

But I can't seem to get it to work. I've padded the month with a 0 and still no dice. The time I'm trying to convert is 4/20/2018 9:08:34 AM and I want it in this format: 2009-04-20T21:18:44Z

NewLastDate = CDate(LastModified) 'generates 4/20/2018 9:08:34 AM 

That's from a VBA script. 'LastModified' is in this format: dddd.ttttt VB/VBA format

  • 写回答

1条回答 默认 最新

  • dongzhang3482 2018-05-02 21:46
    关注

    Go time formats are interesting, you always have to put your formats in terms of (per the docs) https://golang.org/pkg/time/#Parse

    01/02 03:04:05PM '06 -0700
    

    I changed your formats a bit so you could see what is happening. I also would advise checking error returns. It also seems like time.RFC3339 is a good shorthand for what you are looking for on the output side but I may be wrong.

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?