Skip to content

Instantly share code, notes, and snippets.

@davidicus
Created February 2, 2018 21:09
Show Gist options
  • Select an option

  • Save davidicus/b270c9afa02e687b02faef807194b03a to your computer and use it in GitHub Desktop.

Select an option

Save davidicus/b270c9afa02e687b02faef807194b03a to your computer and use it in GitHub Desktop.
Format hour, minutes, and seconds
const leadingZero = (num) => `0${num}`.slice(-2);
const formatTime = (date) =>
[date.getHours(), date.getMinutes(), date.getSeconds()]
.map(leadingZero)
.join(':');
formatTime(new Date(1514727120000))
// -> "07:32:00"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment