answersLogoWhite

0


Best Answer

The easiest way is to use JavaScript's native Date object. That object has a method called 'getTime()' that returns the number of milliseconds since the Unix epoch (Midnight, 1 January 1970, UTC)

To determine how long between two separate events, you'd simply set a pair of variables at the start and the end, and then do the math. This will return the number of milliseconds between the setting of the two variables.

var dateA = new Date().parse('March 21, 2012');

/*thing you want timed goes in here*/

var dateB = new Date().parse('July 15, 2012');

var difference = dateA - dateB;

//difference will now contain 10022400000

You will certainly want to turn that into a more readable format. See the related JSFiddle for complete code on how to work with this object.

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you calculate total time in javascript?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you calculate the four number game ducci in java script?

To calculate the four number game in javaScript ..... I assume you are asking how to calculate the total of the 4 numbers? A simple function calculating the array (assuming you are using an array) is the easiest way. function calculate(array) { var total = 0; for (var counter = 0; counter < array.length; counter = counter + 1) { total = total + array[counter]; } return total; }


What is total distance and total time used to calculate?

Average speed.


What two values you have to calculate speed?

Total distance and total time.


How do you find total distance and total time and then calculate them altogether?

Total Distance: Distance from some fixed point at end - Distance from the same fixed point at start. Total Time: Time at end - Time at start. Not sure what is meant by "calculate them altogether".


How do you calculate total time for a job?

i donnt knoww .?


Which of the following do you calculate when you divide the total distance traveled by the total traveled time?

Speed = Distance/Time


What two measurements must be known to calculate velocity?

The distance travelled, and the time taken.


How do you calculated average speed?

you calculate average speed by dividing the total distance to the total time.


How do you calculate machine utilization rate?

normal working time divided by total working time.


What are the two measure necessary to calculate average speed?

Total distance traveled & total elapsed time.


Why is the average speed the easiest to calculate?

the average speed is the total distance traveled divided by the total time.


How do you you calculate total revenue percentage?

You can calculate the total revenue percentage by substituting the variable X for the monthly revenue, the variable Y for the period of time, and then multiple these to solve for the total revenue percentage.