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?

图片转代码服务由CSDN问答提供 功能建议

我了解如何使用Golang从字符串中解析时间。

当前,我在Go处理的rails / ruby​​中发出一个请求,我在其中传递了一个time参数。

这就是我在rails中所做的事情

  resp = connection.get“ url”,{
 Updated_at:Updated_at \  n} .compact 
   
 
 

updated_at Time.now-1.day

在Go中,这是我解析时间后的解析方式。

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

如果时间看起来像

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

但是Ruby花费的时间看起来像 \ n

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

其中,解析结果为

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

我可以传入参数什么,以便go解析时间 是否正确?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题