Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a jQuery clock that gives the time from 00:00 to 23:00.

Now I want to calculate the time difference between two times. Suppose the "in" time is 11:00, and the "out" time is 16:00.

How do I calculate the time difference in javascript?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
128 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can use Date and setHours like that:

var first = new Date();
first.setHours(0, 11, 0, 0);

var second = new Date();
second.setHours(0, 16, 0, 0);

alert("Diff in seconds: " + (second - first));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...