Skip to content

Instantly share code, notes, and snippets.

@gotoark
Created August 11, 2017 06:16
Show Gist options
  • Save gotoark/ef928497a885299c732d01b81870415f to your computer and use it in GitHub Desktop.
Save gotoark/ef928497a885299c732d01b81870415f to your computer and use it in GitHub Desktop.
Get Current Time in Javascript Original Source : https://stackoverflow.com/a/18229123/5740760
function checkTime(i) {
if (i < 10) {
i = "0" + i;
}
return i;
}
function startTime() {
var today = new Date();
var h = today.getHours();
var m = today.getMinutes();
var s = today.getSeconds();
var ms = today.getMilliseconds();
// add a zero in front of numbers<10
m = checkTime(m);
s = checkTime(s);
ms=checkTime(ms);
return h + ":" + m + ":" + s+ ":" +ms;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment