Created
December 11, 2020 13:13
-
-
Save AitorAlejandro/a5a875927e189e3bc51eab6bb68a5aad to your computer and use it in GitHub Desktop.
javascript configurable timestamp
This file contains hidden or 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 timestamp( | |
{ | |
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep','Oct', 'Nov', 'Dec'], | |
timePad = 2} = {} | |
) { | |
const pad = (n) => n.toString().padStart(timePad, '0'); | |
const d = new Date(); | |
const time = [pad(d.getHours()), | |
pad(d.getMinutes()), | |
pad(d.getSeconds())].join(':'); | |
return [d.getDate(), months[d.getMonth()], d.getFullYear(), time].join(' '); | |
} | |
timestamp(); // something like "21 Aug 2020 21:19:34" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment