Sometimes, we want to format a date or time in TypeScript.
In this article, we’ll look at how to format a date or time in TypeScript.
How to format a date or time in TypeScript?
To format a date or time in TypeScript, we can use the date’s toLocaleString
method.
For instance, we write
const s = new Date().toLocaleString();
to create a new Date
object and then call toLocaleString
on it to return a string that has the formatted datetime of the current time formatted according to the current locale.
Conclusion
To format a date or time in TypeScript, we can use the date’s toLocaleString
method.