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 of your computer.

Question 2

What is an 'epoch'?

An origin of which time started getting counted from.

Question 3

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

The unix time system started on January 1st, 1970. This is the time system used in computers which counts how many seconds or milliseconds has passed since January 1st, 1970.

Question 4

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

00:00:00 UTC on January 1st, 1970

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

It returns with the number of milliseconds passed since January 1st, 1970.

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(x.getTime() > y.getTime()){
		console.log(x + " is most recent!");
	}else if(x.getTime() < y.getTime()){
		console.log(y + " is most recent!");
	}else{
		console.log("They are both the same!");
	}