Format Colon Time from Date
This commit is contained in:
11
snippets/format-colon-time-from-date.md
Normal file
11
snippets/format-colon-time-from-date.md
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
### Format Colon Timestamp from Date (12 hour format)
|
||||||
|
|
||||||
|
Utilizes to12Hour() to transform date.getHours() to 12 hour format and toDigits to maintain double digits for time integers. Formats integers from given date object into a colon time representation.
|
||||||
|
|
||||||
|
```js
|
||||||
|
let toColonTime12 = ( date ) => {
|
||||||
|
let times = [ to12Hour(date.getHours()), date.getMinutes(), date.getSeconds() ];
|
||||||
|
return times.map( t => setDigits(t, 2, 1) ).join(":");
|
||||||
|
}
|
||||||
|
// toColonTime12(new Date()) -> "08:38:00"
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user