Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Practice Object Interaction Checking Out and Returning a Book Solution: checkOut() and returnBook() Methods

Doron Geyer
seal-mask
.a{fill-rule:evenodd;}techdegree
Doron Geyer
Full Stack JavaScript Techdegree Student 13,897 Points

Explanation of the date format given for the challenge.

The challenge requires us to set the due date to the current date plus 2 weeks for the book.

The code provided in the solution is as follows :

const newDueDate = new Date();
  newDueDate.setDate(newDueDate.getDate() + 14);

I understand what its meant to do logically but looking at the output it gives in the console

1599727294801

makes no sense and theres no explanation of what that number represents or how you can process the number.

could someone give me better info on what this is? I can only assume it is providing a breakdown in something like seconds?

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Doron Geyer !

If no string is given when creating the date, it assumes that the date is now so it takes that from your system. The number you see is called a "UNIX timestamp". It represents the number of seconds (or milliseconds) that have elapsed since January 1, 1970. In the case of JavaScript, it uses the millisecond version of the UNIX timestamp.

Here's a link to a timestamp converter.

Documentation on Date.now

Note that when you convert that timestamp to a normal date, the date should be two weeks from when you ran that code because you added 14 days worth of milliseconds to it :smiley:

Hope this helps! :sparkles: