简体   繁体   English

在RoR中解析.Net日期格式

[英]Parsing .Net Date format in RoR

I am currently calling an external API and getting a JSON response. 我目前正在调用外部API并获取JSON响应。 The data has 2 date fields that I need to parse and display in a table in my app. 数据具有2个日期字段,我需要对其进行解析并将其显示在应用程序的表格中。

The issue I am having is that the dates are in .Net format: 我遇到的问题是日期采用.Net格式:

/Date(1377183028730-0400)/

Any suggestions on how I can parse this into a usable RoR format? 关于如何将其解析为可用的RoR格式的任何建议?

That looks like a number of milliseconds from an epoch. 从一个纪元看,这似乎是毫秒数。

You could extract the first part with a regular expression such as 您可以使用正则表达式提取第一部分,例如

if date =~ /Date\((\d+)-(\d+)\)/
  Time.at($1.to_i/1000.0)
end

The latter part might be a timezone indicator. 后一部分可能是时区指示器。

Try using Ruby's strptime function . 尝试使用Ruby的strptime函数 Have a look in the strftime function docs for an explanation of the directives that can be used. strftime函数文档中查看有关可以使用的指令的说明。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM