dtgr3392 2018-09-21 13:58
浏览 73

字符串到日期的转换(带+0530的IST)

I'm not able to convert the string "2017-12-07T20:01:33+0530" into a date format. I'm using RFC3339 and RFC3339Nano but still getting the following error:

0001-01-01 00:00:00 +0000 UTC parsing time "2016-01-17 20:04:05 +0530": hour out of range
IST to UTC: 0001-01-01 00:00:00 +0000 UTC

This is my code:

IST, err := time.LoadLocation("Asia/Kolkata")
if err != nil {
    fmt.Println(err)
    return
}

const longForm = "2006-01-02 15:04:05 +0530"
t, err := time.ParseInLocation(longForm, "2016-01-17 20:04:05 +0530", IST)
fmt.Println(t, err)
fmt.Printf("IST to UTC: %v

", t.UTC())
  • 写回答

1条回答 默认 最新

  • dpxua26604 2018-09-21 14:09
    关注

    The format specifier for the timezone is wrong; you have:

    const longForm = "2006-01-02 15:04:05 +0530"
    

    But the timezone is defined as -0700, not +0530. So that should be:

    const longForm = "2006-01-02 15:04:05 -0700"
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度