Files
30-seconds-of-code/snippets/getColonTimeFromDate.md
Michael Goldspinner 02ecdcb10f Improved getColonTime()
Reduced function code to a single line. Uses Date.toTimeString() and String.slice() to select just the colon time from stirng.
2018-01-13 10:16:09 -05:00

346 B

getColonTimeFromDate

Formats hour, minute, and second time integers from Date into stringified colon representation. Formats hour integer to 12 hour clock and maintains digit lengths to match (HH:MM:SS).

const getColonTimeFromDate = date => date.toTimeString().slice(0, 8)
getColonTimeFromDate(new Date()) // "08:38:00"