开发者

Date formatting a Ruby date from a .NET Webservice

开发者 https://www.devze.com 2023-03-05 06:55 出处:网络
I have a date coming through from a .NET webservice into my Rails app: 2011-05-09T10:57:00+01:00 What date format can I use with Date.strptime which would give me a reliable way o开发者_开发技巧f e

I have a date coming through from a .NET webservice into my Rails app:

2011-05-09T10:57:00+01:00

What date format can I use with Date.strptime which would give me a reliable way o开发者_开发技巧f extracting the date?


Date and DateTime can handle this natively:

DateTime.parse "2011-05-09T10:57:00+01:00"
# => Mon, 09 May 2011 10:57:00 +0100


@Chowlett's answer is good Or you can also try out the "strptime" method on Date. It lets you parse a string in a know format of your choosing.

http://santoro.tk/mirror/ruby-core/classes/Date.html#M000643

0

精彩评论

暂无评论...
验证码 换一张
取 消