开发者

Compare two timestamps per minute difference?

I'm looking to do the following

timestamp1 = Time.now?
timestamp2 = lastSave --- My func would be setting this

if (compare (timestamp1 to timestamp2) > 开发者_运维问答5 seconds

Any ideas on how to do this with JS? Thanks


Are you looking for getting the time?

You can try this in Firebug's console in Firefox:

timestamp1 = new Date();

for (var i = 0; i < 10; i++) console.log(timestamp1);

timestamp2 = new Date();

console.log(timestamp2 - timestamp1);
console.log((timestamp2 - timestamp1) / 1000);

the last one is the number of seconds.


Provided your variable lastSave is a date object.

You can do something like this:

var date1 = new Date();
  if((date2.getTime() - lastSave.getTime()) > 5){
     //do something
  }

getTime() - Number of milliseconds since 1/1/1970 @ 12:00 AM

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜