Hi I'm using this timestamp:
function getTimeStamp() {
var now = new Date();
return ((now.getMonth() + 1) + '/' + (now.getDate()) + '/' + now.getFullYear() + " " + now.getHours() + ':'
+ ((now.getMinutes() < 10) ? ("0" + now.getMinutes()) : (now.getMinutes())) + ':' + ((now.getSeconds() < 10) ? ("0" + now
.getSeconds()) : (now.getSeconds())));
}
and saving pause time here:
localStorage["TmpPause"] = getTimeStamp();
than after a while read time and compare:
var pauseTime = localStorage["TmpPause"];
var resumeTime = getTimeStamp();
var difference = resumeTime.getTime() - pauseTime.getTime(); // This will give difference in milliseconds
var resultInMinute = Math.round(difference / 60000);
alert(resultInMinute);
at the moment I'm unable to calculate the difference in between 2 dates including time. I'm getting error undefined is not a function resumeTime.getTime() ???
Thanks for your help.
getTimeStamp()
does not return a timestamp (such irony), instead it returns a String in this format: "1/20/2014 19:18:28"
This is how you get a timestamp in millisecond: Date.now()
, or even Date().toString()
(time represented in text).
You should store this instead so that you can reuse it later on by doing:
new Date(yourTimestamp); //this returns the original Date object
(newTimestamp - oldTimestamp)/1000/60 //returns difference in minute
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With