Skip to content

Instantly share code, notes, and snippets.

@gnsx
Last active March 29, 2016 08:35
Show Gist options
  • Save gnsx/17e35bd6f74d0b33d77d to your computer and use it in GitHub Desktop.
Save gnsx/17e35bd6f74d0b33d77d to your computer and use it in GitHub Desktop.
JS Code to calculate difference between two time-stamps. Reference : http://stackoverflow.com/questions/1787939/check-time-difference-in-javascript
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Leaflet Label</title>
</head>
<body>
<script>
console.log("Hex");
var date1 = new Date("08/06/2015 02:41:36.150");
var date2 = new Date("08/06/2015 02:45:32.200");
var diff = date2.getTime() - date1.getTime();
var msec = diff;
var hh = Math.floor(msec / 1000 / 60 / 60);
msec -= hh * 1000 * 60 * 60;
var mm = Math.floor(msec / 1000 / 60);
msec -= mm * 1000 * 60;
var ss = Math.floor(msec / 1000);
msec -= ss * 1000;
var msec = msec;
console.log(hh + ":" + mm + ":" + ss + "." + msec);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment