[英]what measure of time do i have here?
If the answer is 8. What is 8? 如果答案是8。什么是8? milliseconds?
毫秒? or must I (time/100)-(ntime/100) to get milliseconds?
还是我必须(time / 100)-(ntime / 100)来获取毫秒?
var time=(+new Date());
for(var i=0;i<100;i++){/*something intensive*/}
var ntime=(+new Date());
console.log('answer: '+((ntime)-time)+('( '+time+' , '+ntime+' )'));
answer: 8 / 1404573120333 >> 1404573120341 答案:8/1404573120333 >> 1404573120341
(+new Date()) A unix timestamp is described as the time in seconds since the epoch (+ new Date())Unix时间戳记被描述为从纪元以来的时间(以秒为单位)
1404573825 would be epoch, seconds since jan1,1970. 1404573825将是一个纪元,距1970年1月1日以来的秒数。
1404573120333 is 3 digits longer, most likely milliseconds since jan1,1970 1404573120333长3位,最可能是自1970年1月1日以来的毫秒
difference therefore too. 因此也是如此。
When turning the Date
value into a number using the +
operator, it will call the valueOf
method . 使用
+
运算符将Date
值转换为数字时,它将调用valueOf
方法 。 The value returned is the number of milliseconds since 1970-01-01 UTC. 返回的值是自1970-01-01 UTC以来的毫秒数。
"The valueOf method returns the primitive value of a Date object as a number data type, the number of milliseconds since midnight 01 January, 1970 UTC."
“ valueOf方法将Date对象的原始值作为数字数据类型返回,即自UTC 1970年1月1日午夜以来的毫秒数。”
The valueOf
method returns the same value as the getTime
method . valueOf
方法返回与getTime
方法相同的值。 The doumentation for the getTime
method has this example for measuring time in milliseconds: getTime
方法的加倍有以下示例,以毫秒为单位测量时间:
var end, start;
start = new Date();
for (var i = 0; i < 1000; i++)
Math.sqrt(i);
end = new Date();
console.log("Operation took " + (end.getTime() - start.getTime()) + " msec");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.