rails中的时间显示格式【转】

在rails中需要显示时间时,格式化时间的方法一般选用strftime,下面是关于strftime的一些介绍

strftime Format Codes

Year Example
%Yyear with century2010
%yyear without century10
%Ccentury number (year divided by 100)20
Month Example
%Bfull month nameJanuary
%babbreviated month nameJan
%hsame as %bJan
%mmonth as number (01-12)
Week Example
%Uweek number of the year, Sunday as first day of week(00-53)
%Wweek number of the year, Monday as first day of week(00-53)
Day Example
 %A full weekday name Wednesday
%a  abbreviated weekday name Wed
%d  day of the month (01-31)
%e  day of the month, single digits preceded by space ( 1-31)
%j  day of the year (001-366)
%w  weekday as a number, with 0 representing Sunday (0-6)
%u  weekday as a number, with 1 representing Monday (1-7) 
Time Example
%Hhour (24-hour clock)(00-23)
%khour (24-hour clock); single digits preceded by space( 0-23)
%Ihour (12-hour clock)(01-12)
%lhour (12-hour clock); single digits preceded by space( 1-12)
%Mminute(00-59)
%Sseconds(00-59)
%peither AM or PMAM
%Ztimezone name or abbreviationEDT
%ztimezone offset from UTC-0400
Summaries Example
%Ddate, same as %m/%d/%y05/16/07
%vdate, same as %e-%b-%Y16-May-2007
%Fdate, same as %Y-%m-%d2007-05-16
%Rtime, 24 hour notation, same as %H:%M18:06
%Ttime, 24 hour notation, same as %H:%M:%S18:06:15
%rtime, am/pm notation, same as %I:%M:%S %p06:06:15 PM
Formatting 
%nnewline character
%ttab character
%%percent character
Less common formats 
%snumber of seconds since the Epoch, UTC
%cnational date and time representation
%+national date and time representation
%xnational date representation
%Xnational time representation
%Gyear with century, starting on first Monday where week has 4 or more days.
%gyear without century, starting on first Monday where week has 4 or more days.
%Vweek number of the year, starting on first Monday where week has 4 or more days.

rails 实现 动态显示时间

2010-12-17 16:25

视图:  

<%= javascript_include_tag :defaults %>
 
<%= periodically_call_remote :url => new_ajax_fun_path, :update =>'result', :frequency => 1 %>
 
 <div id="result"></div>

  

控制器: 

def new
    respond_to do |wants|
      wants.js {render :text => Time.now.strftime("%Y-%m-%d %H:%M:%S")}
    end
end