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 :: CSV total rows ruby 
Ruby :: ruby generate task 
Ruby :: how to differentiate get and post when it has same name in rails 
Ruby :: check validate url ruby 
Ruby :: Ruby Regular Expressions 
Ruby :: ruby abs function programming 
Ruby :: generate view rails 
Ruby :: rails array pop first n elements 
Ruby :: number of trailing zeros in a factorial of a number. 
Ruby :: rails generate model with options 
Ruby :: rails bootstrap background image 
Ruby :: rails humanize date 
Ruby :: simple form change id 
Ruby :: ruby bundler load error 
Ruby :: how to access function defined in model rails 
Ruby :: rails multiple rescue 
Ruby :: rails convert euro to dollar 
Ruby :: how to group array in ruby 
Ruby :: time loop start with non zero in ruby 
Ruby :: ruby puts format 
Ruby :: i am working in ruby 2.6 how to jump to a lower version 
R :: harmonic mean in r 
R :: tbale() in R 
R :: how to import csv file in r 
R :: r language comment 
R :: if not NA in r 
R :: r count distinct dplyr 
R :: r function syntax 
R :: find nas in dataframe r 
R :: how to filter a vector by location in r 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =