toLocaleDateString don't work in TypeScript?

Viewed 390

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