Section 7.22. Time Zone Conversions

7.21. Formatting and Printing Date/Time Values

You can obtain the canonical representation of the date and time by calling the asctime method ("ASCII time"); it has an alias called ctime, for those who already know it by that name.

You can obtain a similar result by calling the to_s method. This is the same as the result you would get if doing a simple puts of a date/time value.

The strftime method of class Time formats a date and time in almost any form you can think of. Other examples in this chapter have shown the use of the directives %a, %A, %U, %W, %H, %M, %S, %I, and %p; we list here all the remaining directives that strftime recognizes:

%b    Abbreviated month name ("Jan") %B    Full month name ("January") %c    Preferred local date/time representation %d    Day of the month (1..31) %j    Day of the year (1..366); so-called "Julian date" %m    Month as a number (1..12) %w    Day of the week as a number (0..6) %x    Preferred representation for date (no time) %y    Two-digit year (no century) %Y    Four-digit year %Z    Time zone name %%    A literal "%" character

For more information, consult a Ruby reference.

The Ruby Way(c) Solutions and Techniques in Ruby Programming
The Ruby Way, Second Edition: Solutions and Techniques in Ruby Programming (2nd Edition)
ISBN: 0672328844
EAN: 2147483647
Year: 2004
Pages: 269
Authors: Hal Fulton

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: