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 date/time will be stored.

Question 2

What is an 'epoch'?

because nial always wants an alt
An epoch is a distinctive period of time for one reason or another.

Question 3

What is a 'Unix timestamp' (also known as 'epoch time')?

The Unix timestamp is time elapsed, in seconds, from the Unix epoch, January 1 1970 @ 00:00:00 UTC time. Leap seconds are ignored.

Question 4

What is the actual date of the epoch for Unix timestamps?

January 1 1970 @ 00:00:00 UTC time

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)?

getTime() returns the number of miliseconds from the start of the Unix epoch

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?

getTime() will give you milisecond values, the bigger of the two will be the more recent, assuming no future dates are involved. Subtract the two numbers, if the number is positive the first date will be the more recent, if its negitive the older date will be first.