Reputation: 714
If the answer is 8. What is 8? milliseconds? or must I (time/100)-(ntime/100) to get milliseconds?
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
(+new Date()) A unix timestamp is described as the time in seconds since the epoch
Upvotes: 0
Views: 43
Reputation: 700312
When turning the Date
value into a number using the +
operator, it will call the valueOf
method. The value returned is the number of milliseconds since 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."
The valueOf
method returns the same value as the getTime
method. The doumentation for the getTime
method has this example for measuring time in milliseconds:
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");
Upvotes: 1
Reputation: 2541
1404573825 would be epoch, seconds since jan1,1970.
1404573120333 is 3 digits longer, most likely milliseconds since jan1,1970
difference therefore too.
Upvotes: 1