Files
30-seconds-of-code/snippets/json-to-date.md
2017-12-16 14:31:04 +02:00

12 lines
326 B
Markdown

### JSON to date
Use `Date()`, to convert dates in JSON format to readable format (`dd/mm/yyyy`).
```js
const jsonToDate = arr => {
const dt = new Date(parseInt(arr.toString().substr(6)));
return `${ dt.getDate() }/${ dt.getMonth() + 1 }/${ dt.getFullYear() }`
};
// jsonToDate(/Date(1489525200000)/) -> "14/3/2017"
```