I want to make code to execute a task 3 seconds before a given time.
Something like this:
var Time = new Date('December 25, 1995 08:00:00:000');
Time.getSeconds() - 3 ;
This should give me 57, instead of -3
I want to make code to execute a task 3 seconds before a given time.
Something like this:
var Time = new Date('December 25, 1995 08:00:00:000');
Time.getSeconds() - 3 ;
This should give me 57, instead of -3
You need to set the seconds via the the dedicated method first - the logic to handle such “rollovers” is already implemented in there - and then you read it again:
// var Time = new Date('December 25, 1995 08:00:00:000');
// careful with the above date format, not all browsers will parse this correctly
// modified version, for this example:
var Time = new Date('1995-12-25T08:00:00');
Time.setSeconds( Time.getSeconds() - 3 );
console.log(Time.getSeconds());