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.

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

报告相同问题?