Skip to content

Instantly share code, notes, and snippets.

@herbowicz
Created March 30, 2018 04:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save herbowicz/dca6bd071d507d8ea0a11e048cd9a1e3 to your computer and use it in GitHub Desktop.
Save herbowicz/dca6bd071d507d8ea0a11e048cd9a1e3 to your computer and use it in GitHub Desktop.
time utility function
function time() {
const now = new Date(),
h = now.getHours(),
m = now.getMinutes(),
s = now.getSeconds()
return `${h === 0 ? 12 : h > 12 ? h - 12 : h}:${(m <= 9 && '0') + m}:${(s <= 9 && '0') + s} ${h >= 12 ? 'PM' : 'AM'}`
}
time()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment