Reduced function code to a single line. Uses Date.toTimeString() and String.slice() to select just the colon time from stirng.
346 B
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"