In my Angular
application, I have to display the date in 'MM/dd/yyyy
' format.
Web API is returning a date in "2020-12-01T00:00:00
" format.
When I use the below line of code, DatePipe
not recognizing the date but if I manually modify the date to "2020-12-01T00:00:00.000Z
" then DatePipe
converting to the expected 'MM/dd/yyyy
' format.
let res = this.datePipe.transform(new Date('2020-12-01T00:00:00'),'MM/dd/yyyy');
let res = this.datePipe.transform(new Date('2020-12-01T00:00:00.000Z'),'MM/dd/yyyy');
The first one is not working and the second one is working. But my API returning data in the first format.
Can someone help me to change the date from first to the second format using Typescript?
new Date('...')
. Tryconsole.log(isNaN(new Date('2020-12-01T00:00:00')))
. If the reuslt is true then you know the browser is the culprit.