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

Categories

0 votes
129 views
in Technique[技术] by (71.8m points)

javascript - calculate time difference

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

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

1 Answer

0 votes
by (71.8m points)

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));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...