Hello Friends 👋,

Welcome To Infinitbility! ❤️

To get the current date in typescript has the Date() object it will return every time the current date and time when we use it.

we have to just write new Date() and it returns the date object where we get a year, month, date, hours, minutes, and seconds.

let today: object = new Date();
console.log(today); // 2022-02-06T08:05:49.292Z

Now, we know we have the current date but we can’t show the same to also users.

To format, we have multiple packages like Day.js, and Moment.js.

But if wanna follow a custom formater follow the below code.

Below example will format date in yyyy-mm-dd.

let today: object = new Date();
let date: string = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
console.log(date) // '2022-2-6'

Output

typescript, current, date, example
TypeScript, get current date example.

Thanks for reading…