Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

substract 5 minute from current Date and time javascript

Tags:

javascript

I have problem while substracting time from current date. My Code looks like:

var d = new Date(),
year = d.getUTCFullYear(),
month = ('0'+(d.getUTCMonth()+1)).slice(-2),
day = ('0'+d.getUTCDate()).slice(-2),
hour = ('0'+d.getUTCHours()).slice(-2),
minute = ('0'+d.getUTCMinutes()).slice(-2),
second = ('0'+d.getUTCSeconds()).slice(-2);

var startDate = year+'/'+month+'/'+day+'-'+hour+':'+minute+':'+second;
console.log(startDate);
like image 521
Karan Avatar asked Dec 19 '22 19:12

Karan


1 Answers

You can simply use like below

var fiveMinuteAgo = new Date( Date.now() - 1000 * (60 * 5) )
like image 88
Hax0r Avatar answered Jan 08 '23 19:01

Hax0r