C#将JSON日期序列化为Ruby [英] c# serialized JSON date to ruby
本文介绍了C#将JSON日期序列化为Ruby的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个C#应用程序,该应用程序将其DTO序列化为JSON并将其发送给Ruby,以便将其处理.现在序列化日期的格式如下:
I have a C# application that serializes its DTOs to JSON and sends them accros the wire to be processed by Ruby. Now the format of the serialized date is like so:
/Date(1250170550493+0100)/
当它到达Ruby应用程序时,我需要将此字符串表示形式转换回日期/日期时间/时间(无论在Ruby中是什么).有什么想法我会怎么做吗?
When this hits the Ruby app I need to cast this string representation back to a date/datetime/time (whatever it is in Ruby). Any ideas how I would go about this?
干杯,克里斯.
推荐答案
您可以解析自该时期以来的毫秒数,例如:
You could parse out the milliseconds since the epoch, something like:
def parse_date(datestring)
seconds_since_epoch = datestring.scan(/[0-9]+/)[0].to_i / 1000.0
return Time.at(seconds_since_epoch)
end
parse_date('/Date(1250170550493+0100)/')
您仍然需要处理时区信息(+0100
部分),所以这是一个起点.
You'd still need to handle the timezone info (the +0100
part), so this is a starting point.
这篇关于C#将JSON日期序列化为Ruby的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文