dsjq6977 2016-08-10 22:48
浏览 55
已采纳

Ruby和Golang时间解析

I understand how to parse times from strings using Golang.

Currently, I make a request in rails/ruby that is handled by Go, in which I pass in a time parameter.

This is what I'm doing in rails

  resp = connection.get "url", {
    updated_at: updated_at
  }.compact

and updated_at is Time.now - 1.day.

In Go, this is how I'm parsing the time, after getting it out.

updatedAt, err := time.Parse("2006-01-02 15:04:05 -0700 MST", updatedAtVar)

The above works if time looks like

2014-11-17 23:02:03 +0000 UTC

but Ruby spits out a time that looks like

2016-08-10 22:29:51 +0000

which, when parsing results in

0001-01-01 00:00:00 +0000 UTC

What can I pass into my param such that go will parse the time correctly?

  • 写回答

1条回答 默认 最新

  • dongzhun1857 2016-08-10 23:26
    关注

    The format string provided in the docs contains some redundant information (MST and -0700 in particular convey the same information—a UTC offset in hours*100+minutes).

    So, just leave "MST" out of your format string.

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

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?