Dates and Times
Ruby has three separate classes to represent date and time data: Time, Date, and DateTime.
-
Time represents a specific moment in time, and you can retrieve both date and time information based on that. The Time class is based on a library that is common to Unix systems and is used by many programming languages.
-
Date represents a date only with no time information attached. It’s useful for calendar arithmetic that doesn’t depend on the time of day. You need require "date" to use the Date class.
-
DateTime also represents a specific moment in time but uses a different internal representation than Time. DateTime is now considered deprecated—at one point it had a more complete API than Time, but that is no longer true. Currently, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access