Wrong date with angular material's date picker

后端 未结 4 540
孤独总比滥情好
孤独总比滥情好 2021-01-04 09:00

I use the datepicker to pick a date and send it to the server.

When I log the JS value I get the correct result:

Tue Mar 22 2016 00:00:00 GMT+0100 (M         


        
4条回答
  •  迷失自我
    2021-01-04 09:48

    If suppose am selecting a date like Tue Aug 06 2019 00:00:00 GMT+0530 (India Standard Time),
    am getting 2019-08-05T18:30:00.000Z. ( which in my case previous date with respect to the selected date)
    I made use of toLocalDateString() to do the job.

        // this.date = 2019-08-05T18:30:00.000Z
        const converted = new Date(this.date).toLocaleDateString(); 
        console.log(converted); // 8/6/2019 (MM/DD/YYYY) format
    

提交回复
热议问题