Run ❯
Get your
own
website
Result Size:
625 x 565
×
Change Orientation
Save Code
Change Theme, Dark/Light
Go to Spaces
<!DOCTYPE html> <html> <body> <h2>JavaScript Dates</h2> <p>parse() parses a date string and returns the number of milliseconds since midnight January 1, 1970.</p> <p>Calculate the number of years between March 21, 2012 and January 1, 1970:</p> <p id="demo"></p> <script> // Calculate milliseconds in a year const minute = 1000 * 60; const hour = minute * 60; const day = hour * 24; const year = day * 365; // Compute years const d = Date.parse("March 21, 2012"); let years = Math.round(d / year); document.getElementById("demo").innerHTML = years; </script> </body> </html>