Transforming Datetime into month, day and year?

后端 未结 7 1965
北恋
北恋 2020-12-13 04:36

I can\'t seem to find this and I feel like it should be easy. In Ruby on Rails, how do I take:

2010-06-14 19:01:00 UTC

and turn it into

相关标签:
7条回答
  • 2020-12-13 05:24

    Time and date formats in rails:

    Date

    ====

    db:‘%Y-%m-%d’   2008-08-20
    
    long_ordinal:‘&proc’      August 20th, 2008
    
    long:‘%B %e, %Y’  August 20, 2008
    
    rfc822:‘%e %b %Y’   20 Aug 2008
    
    number:‘%Y%m%d’     20080820
    
    short:‘%e %b’      20 Aug
    

    DateTime

    ====

    db:‘%Y-%m-%d’   2008-08-20 16:56:21
    
    long_ordinal:‘&proc’      August 20th, 2008 16:56
    
    long:‘%B %e, %Y’  August 20, 2008 16:56
    
    rfc822:‘%e %b %Y’   Wed, 20 Aug 2008 16:56:21 -0600
    
    number:‘%Y%m%d’     20080820165621
    
    short:‘%e %b’      20 Aug 16:56
    

    Time

    ====

    db:‘%Y-%m-%d %H:%M:%S’         2008-08-20 16:56:21
    
    long_ordinal:‘&proc’           August 20th, 2008 16:56
    
    long:‘%B %d, %Y %H:%M’           August 20, 2008 16:56
    
    rfc822:‘%a, %d %b %Y %H:%M:%S %z’  Wed, 20 Aug 2008 16:56:21 -0600
    
    short:‘%d %b %H:%M’               20 Aug 16:56
    
    number:‘%Y%m%d%H%M%S’              20080820165621
    
    time:‘%H:%M’                     16:56
    

    for example:

    <%= news.created_at.strftime("%B %d, %Y %H:%M") %>
    

    Thanks http://onrails.org/2008/08/20/what-are-all-the-rails-date-formats.html

    0 讨论(0)
提交回复
热议问题