Created
February 2, 2018 21:09
-
-
Save davidicus/b270c9afa02e687b02faef807194b03a to your computer and use it in GitHub Desktop.
Format hour, minutes, and seconds
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
| 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