Last active
December 31, 2015 11:59
-
-
Save genediazjr/7983639 to your computer and use it in GitHub Desktop.
A simple yyyyMMddHHmmssSSS timestamp generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getTimestamp () { | |
var date = new Date(); | |
var year = date.getFullYear(); | |
var month = (date.getMonth() + 1) + ''; | |
var day = date.getDate() + ''; | |
var hr = date.getHours() + ''; | |
var min = date.getMinutes() + ''; | |
var sec = date.getSeconds() + ''; | |
var ms = date.getMilliseconds() + ''; | |
if (month.length === 1) { | |
month = '0' + month; | |
} | |
if (day.length === 1) { | |
day = '0' + day; | |
} | |
if (hr.length === 1) { | |
hr = '0' + hr; | |
} | |
if (min.length === 1) { | |
min = '0' + min; | |
} | |
if (sec.length === 1) { | |
sec = '0' + sec; | |
} | |
if (ms.length === 1) { | |
ms = '00' + ms; | |
} else if (ms.length === 2) { | |
ms = '0' + ms; | |
} | |
return year + month + day + hr + min + sec + ms; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment