Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8462493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:10:38+00:00 2026-06-10T14:10:38+00:00

im trying to get the current time timeNow in javascript and at the end

  • 0

im trying to get the current time timeNow in javascript and at the end of the script get
timeEnd which is when the script finished executing for example:

newDate = new Date();
timeNow = newDate.getTime();

for(i=0; i < 5; i ++){

    console.log("printing" + i);
}

timeEnd = timeNow - newDate.getTime();

console.log(timeEnd);

i want to get the time it took to excute this script in seconds or milliseconds, but the result is 0. i don’t see why, can you help me thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T14:10:39+00:00Added an answer on June 10, 2026 at 2:10 pm

    The Date object does not keep ticking once it’s constructed, it only represents a single instant in time.

    You need to re-evaluate the time at the end of the script and then compare that value with the first one.

    Note that on modern ES5 browsers you can use the “static” Date.now() function to get the current time. This is less expensive that constructing a whole new Date object. On older browsers you can emulate this function with this shim:

    Date.now = Date.now || function() {
        return +(new Date);
    };
    

    At which point the required code becomes:

    var start = Date.now();
    
    // do your stuff here
    ...
    
    var end = Date.now();
    
    var elapsed = end - start;
    

    FWIW, your simple loop reports 2ms when run on the Chrome console on my laptop.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to get the current time in a bash script and store
I'm trying to get the current user login status via javascript sdk but I
I'm trying to get the current time as TimeStamp without success. I have this
I'm trying to get the current time via DateTime.Now.ToString(yyyy-MM-dd hh:mm:ss) However, this is spitting
i'm trying to get the current date and time formatted, this is my code:
I am using a JavaScript Date class & trying to get the current date
I'm new to C/C++, I've been using python, And I'm trying to get current
I am trying to get correctly the difference of the current time and a
I am trying to get the current time of a running animation but I
Hi I'm trying to get the current time including the nanoseconds in actionscript 3

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.