开发者

Why is this Time.parse failing

开发者 https://www.devze.com 2023-01-15 13:43 出处:网络
>> events.first.datetime => Wed Sep 15 19:0开发者_StackOverflow0:00 -0400 2010 >> Time.parse(events.first.datetime)
>> 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

精彩评论

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