Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

toLocaleDateString don't work in TypeScript?

How to make toLocaleDateString compatible with TypeScript, I am tying to get the current day in number and the only way to convert to numeric is to use to local string which is not compatible with date, I tried to make a separate function instead of chaining but it is not working?

let currentDay = new Date(today.getFullYear(), today.getMonth(), today.getDate()).valueOf().toLocaleDateString('en-US', { day: 'numeric' })
like image 426
Richardson Avatar asked Oct 15 '25 08:10

Richardson


1 Answers

It is compatible with TypeScript. Delete the .valueOf(). You are converting to a number there, that's what's causing you problems.

let currentDay = new Date(today.getFullYear(), today.getMonth(), today.getDate()).toLocaleDateString('en-US', { day: 'numeric' })
like image 197
Paarth Avatar answered Oct 16 '25 22:10

Paarth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!