I'm trying to figure out if 10 minutes go by, then an action happens. Right now all I have is this, I don't understand the timestamp too well. Such as 1370246236916...Where is the hour, day, year and minutes or seconds etc.
var ten_mins = new Date().getTime();
var time = data_base_time;
var time_to_ago = time - new Date().getTime()+100000;
if( time >= time_to_ago){
//Ten minutes went by
}
I'm trying to figure out if 10 minutes go by, then an action happens. Right now all I have is this, I don't understand the timestamp too well. Such as 1370246236916...Where is the hour, day, year and minutes or seconds etc.
var ten_mins = new Date().getTime();
var time = data_base_time;
var time_to_ago = time - new Date().getTime()+100000;
if( time >= time_to_ago){
//Ten minutes went by
}
Share
Improve this question
asked Jun 3, 2013 at 7:45
BrianBrian
1511 gold badge3 silver badges14 bronze badges
1
- 2 getTime returns milliseconds since 1970-01-01, if you want 10 minutes, the constant should be 10*60*1000 = 600000 milliseconds. – Joachim Isaksson Commented Jun 3, 2013 at 7:48
3 Answers
Reset to default 5Why not use setTimeout()
:
window.setTimeout(function() {
// 10 minutes have gone by. Execute a function here.
}, 600000);
The getTime() method returns the number of milliseconds between midnight of January 1, 1970 and the specified date.
var current = new Date().getTime();
var ten_minutes_from_now = new Date().getTime() + 600000;
if(ten_minutes_from_now >= current) window.alert('Ten minutes have passed');
timeStamp event property returns the number of in milliseconds since midnight of January 1, 1970
Mon, 03 Jun 2013 07:57:16 GMT means 1370246236916 milliseconds from January 1, 1970.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742317677a4421165.html
评论列表(0条)