Search
 
SCRIPT & CODE EXAMPLE
 

RUBY

how to format date and time in rails

Date (Year, Month, Day):
  %Y - Year with century (can be negative, 4 digits at least)
          -0001, 0000, 1995, 2009, 14292, etc.
  %C - year / 100 (round down.  20 in 2009)
  %y - year % 100 (00..99)

  %m - Month of the year, zero-padded (01..12)
          %_m  blank-padded ( 1..12)
          %-m  no-padded (1..12)
  %B - The full month name (``January'')
          %^B  uppercased (``JANUARY'')
  %b - The abbreviated month name (``Jan'')
          %^b  uppercased (``JAN'')
  %h - Equivalent to %b

  %d - Day of the month, zero-padded (01..31)
          %-d  no-padded (1..31)
  %e - Day of the month, blank-padded ( 1..31)

  %j - Day of the year (001..366)

Time (Hour, Minute, Second, Subsecond):
  %H - Hour of the day, 24-hour clock, zero-padded (00..23)
  %k - Hour of the day, 24-hour clock, blank-padded ( 0..23)
  %I - Hour of the day, 12-hour clock, zero-padded (01..12)
  %l - Hour of the day, 12-hour clock, blank-padded ( 1..12)
  %P - Meridian indicator, lowercase (``am'' or ``pm'')
  %p - Meridian indicator, uppercase (``AM'' or ``PM'')

  %M - Minute of the hour (00..59)

  %S - Second of the minute (00..59)

  %L - Millisecond of the second (000..999)
  %N - Fractional seconds digits, default is 9 digits (nanosecond)
          %3N  millisecond (3 digits)
          %6N  microsecond (6 digits)
          %9N  nanosecond (9 digits)
          %12N picosecond (12 digits)
Comment

format date rails created long

active_record.created_at.to_formatted_s(:long)
Comment

PREVIOUS NEXT
Code Example
Ruby :: length validation rails 
Ruby :: table name from rails console 
Ruby :: rails array include another array 
Ruby :: rails validate presence 
Ruby :: ruby different ways to run string interpolation 
Ruby :: rails form_tag 
Ruby :: auto load path rails 
Ruby :: rails array sort 
Ruby :: generate csv ruby 
Ruby :: ruby downcase 
Ruby :: rails check routes in console 
Ruby :: rails generate rake task 
Ruby :: rails check if a URL is valid 
Ruby :: ruby string trmi 
Ruby :: params except rails 
Ruby :: ruby rails find data field type 
Ruby :: ruby conditionals 
Ruby :: rails 6 TypeError: $(...).tooltip is not a function 
Ruby :: rails not_found 
Ruby :: ruby array last 
Ruby :: rails pass params in url 
Ruby :: sequel ruby alias table 
Ruby :: Rails, using whenever gem in development 
Ruby :: ruby on rails freecodecamp 
Ruby :: how to open ruby console 
Ruby :: rails-react syntax error jsx not enabled 
Ruby :: call api in ruby 
Ruby :: rails ngrok blocked host 
R :: remove elements from character vector in r 
R :: r optim 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =