I need to calculate the time difference between two timestamps in the following format:
yyyyMMddHHmmss
for example I have
var lastExecution = 20150116165100; //--- 16:51:00 16/01/2015
var currentTime = 20150116170120; //--- 17:01:20 16/01/2015
In this particular case, the elapsed time is 00:10:20
.
How can I calculate it in js? Do I have to convert it in some other format before I can proceed?
What I want to achieve is to be able to set a minimum elapsed time in a variable, if the time elapsed between the lastExecution and now is greater than the minumum elapsed time I want to launch a particular function:
minTime = 00000000001000; //--- 10 minutes
var lastExecution = getLastExecutionTimestamp();
var currTime = getCurrentTimestamp();
if((currTime - lastExecution) > minTime){ //--- I need help here to calculate the elapsed time
doSomething();
}
getLastExecutionTimestamp()
and getCurrentTimestamp()
return a numeric timestamp in yyyyMMddHHmmss
format, for example 20150116165100
Thank you