Home > database >  toLocaleDateString don't work in typescript?
toLocaleDateString don't work in typescript?

Time:11-10

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 witch is not compatible with date, I tried to make a separate function instead of chaining but it not working ?

let currentDay = new Date(today.getFullYear(), today.getMonth(), today.getDate()).valueOf().toLocaleDateString('en-US', { day: 'numeric' })
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

CodePudding user response:

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' })
  • Related