简体   繁体   中英

Convert ISO8601 date time format in rails 4

I am requesting a list of objects from Salesforce via the Restforce API in my Rails 4 application. When I request the date and time field on each object, I receive in in iso8601 format. For example, in my view, the date and time are displayed like this:

2014-10-03T22:37:15.000+0000    

In my view I have:

<td><%= transaction.Recorded_On__c %></td>

I would like to be able to somehow call strftime on Recorded_On__c however, I get a undefined method error when I do that currently. I've also tried date_select(transaction.Recorded_On__c) and receive syntax errors. In the end I would like to have the date displayed as month("Feb"), day("20"), year("2014)".

You can use I18n, you have to create en.yml that you can find here:

I18n Rails

<td><%= l transaction.Recorded_On__c.to_date, format: :long %></td>

首先,您需要将字符串转换为日期或时间,然后-使用I18n.l方法指定所需的格式。

<td><%= I18n.l "2014-10-04T22:49:02+04:00".to_time, format: "%b.%d.%Y" %></td>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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