To format a Date in typescript, you can use the toLocaleString()
function or use a third-party library like moment.js
.
Here's an example of how to use the toLocaleString()
function to format a Date object:
index.ts192 chars6 lines
Output: '2021-12-18 20:15:43'
If you prefer to use the moment.js
library, here's an example:
index.ts154 chars6 lines
Output: '2021-12-18 20:15:43'
Note that this solution requires you to install the moment.js
library using a package manager like npm.
gistlibby LogSnag