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 trialDoron Geyer
Full Stack JavaScript Techdegree Student 13,897 PointsExplanation 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
Treehouse TeacherHi 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
Hope this helps!
Doron Geyer
Full Stack JavaScript Techdegree Student 13,897 PointsDoron Geyer
Full Stack JavaScript Techdegree Student 13,897 PointsThanks Jennifer Nordell , glad to see you still here teaching the masses better ways to do things, miss having you in the JavaScript slack!