• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

158
Views
Date getSeconds returns 0 when subtracting to another Date getSeconds
function returntime() {
  var start = new Date().getSeconds();
  var end = new Date().getSeconds();
  var totaltime = end - start;
  document.getElementById("Answer").innerHTML = totaltime;
}

The totaltime return 0 but when i put start or end it shows the output.

almost 3 years ago · Juan Pablo Isaza
2 answers
Answer question

0

There is no delay between both statements.

var start = new Date().getSeconds();
  var end = new Date().getSeconds();

See this image for debugger output

almost 3 years ago · Juan Pablo Isaza Report

0

You ask for seconds. The code runs faster than a second. For example, you get 9 seconds at the start and 9 seconds in the end. If you ask for the milliseconds you will see that you will have a different result.

almost 3 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error