JavaScript Date API Worksheet
Questions
This reference may be helpful in understanding how you can work with Date objects.
Question 1
If you invoke the Date constructor without passing in any parameters, what date will be stored in the object that is returned?
The current time when the function is run (down to the ms).
Question 2
What is an 'epoch'?
"a memorable event or date" per
Meriam-Webster Dictionary.
In the context it was used in the video, it is refering to the Unix epoch which is the start of Unix Time (Jan 1, 1970).
Question 3
What is a 'Unix timestamp' (also known as 'epoch time')?
The number of millisceconds that have elapsed since the Unix epoch to the designated time.
Question 4
What is the actual date of the epoch for Unix timestamps?
January 1, 1970 00:00:00
or 0 ms
If this isn't the answer you were looking for I fear I misunderstood the question.
Question 5
What does the getTime() method of a date object return (refer to the link that was mentioned above, or find another reference on the Date object in JavaScript)?
"Returns the number of ms since the epoch and the designated time." -
w3schools.
Also known as the Unix timestamp or epoch time from Question 3.
Question 6
If you are working with 2 date objects, how could you use the getTime() method to determine if one date is more recent than the other?
If you subtract time1.getTime() from time2.getTime() and get a NEGATIVE number, time.1 is closer to the epoch (meaning time2 is more recent.)
If you subtract time1.getTime() from time2.getTime() and get a POSITVE number, time.1 is further from the epoch (meaning time1 is more recent.)