convert a date to a string in typescript

To convert a date to a string in TypeScript, you can use the toString() method of the Date object. In the parentheses of the method, you can specify the format in which you want the date to be displayed. Here's an example:

index.ts
const date = new Date();

const dateString = date.toString(); // "Wed Jun 09 2021 19:38:59 GMT+0200 (Central European Summer Time)"
132 chars
4 lines

In this example, the toString() method returns a string that represents the current date in the default format.

You can also use various libraries to format the date in a specific format, such as moment.js or date-fns.

gistlibby LogSnag