In this lesson, our instructor talks about dates and times. First, he talks about dates, times, time class, methods of the time class, components of a time, convert time to array, and creating a new time. Then he talks about more methods of the time class, date library, initializing new date, parsing dates, today's date, and tomorrow's date. Lastly, he lectures on count down, count up, components of a date, converting to datetime, initializing a datetime, count converting to time.
The Date library loads up two classes Date and DateTime
use new to create a new date object
the parse method allows you to represent date and time through a date object
the today method will create a new date object denoting the present date
Methods to define components of a date: year, month, day, sunday?, thursday?
Dates and Times
Lecture Slides are screen-captured images of important points in the lecture. Students can download and print out these lecture slide images to do practice problems as well as take notes while watching the lecture.
What at does is, you pass in a value of time, and this creates a new Time object with the given time you pass in.0128
Time is the number of seconds from epoch, so if I do Time.at with 0, the time it's going to give me is 1969, December 31st, 4 o'clock, and here is your time zone.0137
If I pass in this huge number, say 1.2 billion seconds, it's going to get me 2008.0157
I can also do Time.at with...call Time.now, which will get me the current time, then to_i to convert it to number of seconds in integers, and then I can pass it, and it will get me the exact same object, essentially.0172
One question you might have is, "What is this number second from epoch?"0187
I'm loading up the epoch converter--epochconverter.com.0197
You will see that, if I reload it...actually, in real time, notice that it tells me the epoch time, and it's this huge, huge number--in the billions.0204
But, you can also convert this epoch to human-readable; you take this number, you can click this timestamp, and it will say...for my time zone right now, it is Monday, October 15th, from that timestamp.0217
Now, what is this number, essentially?--let's go down here--what is epoch time?0232
This is the UNIX epoch, or UNIX time, or POSIX time, or UNIX timestamp.0239
To create a Date object, it is denoted with the given calendar date; so, by default, it does have some values if you don't pass anything; I can just do Date.new; it will get me a year that is -4712, a month of 1, and a day of 1.1030
So...you probably want to add in your own values.1047
I have an example here: all you do is call Date.new, and I'm passing in 2011, month is 10, day is 10; it's going to create a new Date object.1052