// Convert today and Xmas to the number of milliseconds since Jan 1 1970
// and then subtract the two numbers

diff = Xmas.getTime() - today.getTime();

This line of code calculates the difference in time (milliseconds) between the Xmas object and the today object. The getTime() method of the date object returns the number of milliseconds that have passed since January 1st, 1970 (known as the epoch date). Because we have two relative times in milliseconds, we can then go ahead and subtract the two and get the difference between the two dates.

The two method calls to getTime() are performed on each object first, due to precedence. After the two function calls, the returned values are subtracted, and the final value is assigned to diff.

Close window