English 中文(简体)
我如何/是否应该处理一个罗R日时“类型”/“领域”?
原标题:How could/should I handle a RoR datetime "type"/"field"?

我正在使用铁路3.1.0,我希望以适当方式展示日期和时间。 这就是说,我储存了RoRdate (UTC)数据,我产出如@user.last_sign_in_at。 见2012-01-14 00:58:18 UTC。 然而,我要分别列出产出日期和时间。

象<代码>Day:2012-01-14和time:00:58:18

www.un.org/Depts/DGACM/index_spanish.htm • 如何用“Exract”日期和时间组成“RoRdatetime“类型”/“field”? 一般而言,我如何能够/应该如何处理?

最佳回答

值得注意的是:

time_ago_in_words(3.minutes.from_now)       # => 3 minutes
time_ago_in_words(Time.now - 15.hours)      # => about 15 hours
time_ago_in_words(Time.now)                 # => less than a minute

rel=“nofollow”http://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html

问题回答

http://apidock.com/ruby/Datetime/strftime”rel=“nofollow” 方法:

@user.last_sign_in_at.strftime("%l:%M%p") # => 9:37AM

@user.last_sign_in_at.strftime("%m/%d/%Y") # => 01/14/2012

您也可以通过向您的召集人/初创者增加类似内容,将时间方法延伸到:

Time::DATE_FORMATS[:verbose] = "%A, %B %d, %Y @ %I:%M %p"

这样,你就不必记住具体的形式说明。 之后,您认为:

@user.last_sign_in_at.to_formatted_s(:verbose)

这里与铁路违约s有关。

• 更多地提到@iWasRobbed的答复

@user.last_sign_in_at.strftime http://www.foragoodstrftime.com/“rel=“nofollow”>。

也可以检查gem,由Ryan Bigg检查。 这里有许多选择,以不同的形式显示时间和日期。

您可使用<代码>~_date.to_s(:db),以您的数据库格式输入。





相关问题
Mysql compaire two dates from datetime?

I was try to measure what is faster and what should be the best way to compare two dates, from datetime record in MySql db. There are several approaches how to grab a date from date time, but I was ...

iPhone Date Picker rolls over to 2010 on December 27th?

So I implemented a UIDatepicker in one of my applications for scheduling and autodialing teleconferences... everything is pretty much ready to go except, while testing I noticed that when the date ...

Convert date Python

I have MMDDYY dates, i.e. today is 111609 How do I convert this to 11/16/2009, in Python?

specifying date format when using $form->inputs() in CakePHP

I am wondering if there is a way to specify the date format in the forms created using CakePHP s $form->inputs(); Please note that this is not the individual $form->input() but instead $form->inputs() ...

NSDateFormat, super simple! Where am I screwing up?

Ok, this is really simple, maybe I m a getting a bit burnt out, but seems like it should work, Query XML feed, put out date string, format, display in a cell. The issue is I m a getting a NULL ...

sqlite writing a date into an email

I am exporting a date value from sqlite and placing it into an email. The date appears like this 279498721.322872 I am using Objective C in an Iphone App. Does anyone know how to make this export ...

热门标签