Skip to content

Instantly share code, notes, and snippets.

@iSkore
Last active September 12, 2016 16:14
Show Gist options
  • Save iSkore/36322e859f7e566ae880 to your computer and use it in GitHub Desktop.
Save iSkore/36322e859f7e566ae880 to your computer and use it in GitHub Desktop.
Excellent time stamp function
function getNow( off ) {
let date = new Date();
date.setTime( date.getTime() + ( 3600000 * off || 0 ) );
let y = date.getFullYear(),
mo = date.getMonth() + 1,
d = date.getDate(),
h = date.getHours(),
m = date.getMinutes(),
s = date.getSeconds(),
mm = date.getMilliseconds();
mo = ( mo < 10 ? '0' : '' ) + mo;
d = ( d < 10 ? '0' : '' ) + d;
h = ( h < 10 ? '0' : '' ) + h;
m = ( m < 10 ? '0' : '' ) + m;
s = ( s < 10 ? '0' : '' ) + s;
return y + mo + d + h + m + s + mm;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment