admin管理员组文章数量:1356413
starttime=(new Date()).getTime();
endtime=(new Date()).getTime();
(endtime-starttime )/1000
will give a value.What is this value and why is it divided by 1000
starttime=(new Date()).getTime();
endtime=(new Date()).getTime();
(endtime-starttime )/1000
will give a value.What is this value and why is it divided by 1000
Share Improve this question asked Jan 3, 2011 at 10:44 RajeevRajeev 47k80 gold badges191 silver badges288 bronze badges4 Answers
Reset to default 2Well, in this particular case the value will be 0.
you need to divide it by 1000 because time is represented in miliseconds, so to get the seconds you need to perform the transformation 1s = 1000ms
That code is calculating the number of seconds that have elapsed between two dates. The division by 1000 is there because the getTime()
method returns a value measured in millseconds.
The code is actually needlessly long-winded. To get the milliseconds that have elapsed between two Date
objects, you can just use the -
operator on the Date
s themselves:
var start = new Date();
// Some code that takes some time
var end = new Date();
var secondsElapsed = (end - start) / 1000;
value=millisecond delta, it is divided to turn the delta into seconds
Date getTime() gives the number of milliseconds since 1970 (Epoch)
Divide the difference by 1000 and you get seconds
本文标签: Time calculation in javascriptStack Overflow
版权声明:本文标题:Time calculation in javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744039775a2580448.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论