views:

21

answers:

2

Hello, 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

A: 

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.

動靜能量
A: 

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

SteD