Skip to content

Instantly share code, notes, and snippets.

@AitorAlejandro
Created December 11, 2020 13:13
Show Gist options
  • Save AitorAlejandro/a5a875927e189e3bc51eab6bb68a5aad to your computer and use it in GitHub Desktop.
Save AitorAlejandro/a5a875927e189e3bc51eab6bb68a5aad to your computer and use it in GitHub Desktop.
javascript configurable timestamp
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