开发者

Why is this Time.parse failing

>> events.first.datetime
=> Wed Sep 15 19:0开发者_StackOverflow0:00 -0400 2010
>> Time.parse(events.first.datetime)
NoMethodError: private method `gsub!' called for Wed Sep 15 19:00:00 -0400 2010:Time


Time#parse creates a Time object out of a String, which it takes as its first argument. You already have a Time object, so Time.parse doesn't know what to do with it.

In order to format the date like you want it, take a look at Time#strftime. You can format it like you want with the format string:

events.first.datetime.strftime("%A %B %d, %Y at %I:%M %p")

Take a look at the manual entry for strftime for other format specifiers.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜