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 date will be set to the current date and time at the exact moment it is invoked.

Question 2

What is an 'epoch'?

An epoch is a reference point in time from when a computer system measures time intervals.

Question 3

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

A Unix timestamp is the number of milliseconds that have elapsed since the Unix epoch.

Question 4

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

The actual date of the epoch for Unix timestamps is January 1, 1970, at 00:00:00 UTC.

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

The getTime() method returns the number of milliseconds since the Unix epoch (January 1, 1970, 00:00:00 UTC).

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?

The getTime() method can be used to compare the two date objects by comparing their millisecond values. The date with the larger millisecond value is more recent than the other.