display today's date in month day, year format in typescript

You can use the toLocaleDateString function on a Date object to display today's date in the desired format. Here's an example:

index.ts
const today = new Date();
const options = { month: 'short', day: 'numeric', year: 'numeric' };
const formattedDate = today.toLocaleDateString('en-US', options);

console.log(formattedDate); // Output: Oct 04, 2022
214 chars
6 lines

In the options object, you can customize the output by specifying which date components you want to include (month, day, year) and their format (short, long, numeric, etc.).

You can adjust the en-US argument to display the output in a different locale.

gistlibby LogSnag