Nest all content into snippets
This commit is contained in:
20
snippets/js/s/get-colon-time-from-date.md
Normal file
20
snippets/js/s/get-colon-time-from-date.md
Normal file
@ -0,0 +1,20 @@
|
||||
---
|
||||
title: Get colon time from date
|
||||
type: snippet
|
||||
language: javascript
|
||||
tags: [date,string]
|
||||
cover: digital-nomad-5
|
||||
dateModified: 2020-10-19T22:49:51+03:00
|
||||
---
|
||||
|
||||
Returns a string of the form `HH:MM:SS` from a `Date` object.
|
||||
|
||||
- Use `Date.prototype.toTimeString()` and `String.prototype.slice()` to get the `HH:MM:SS` part of a given `Date` object.
|
||||
|
||||
```js
|
||||
const getColonTimeFromDate = date => date.toTimeString().slice(0, 8);
|
||||
```
|
||||
|
||||
```js
|
||||
getColonTimeFromDate(new Date()); // '08:38:00'
|
||||
```
|
||||
Reference in New Issue
Block a user