Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wrong date with angular material's date picker

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 (Mitteleuropäische Zeit)

but in the ajax request it is

2016-03-21T23:00:00.000Z

I don't modify the values, just giving the object to angulars http function.

Does Angular need some configuration to handle it?

like image 421
cre8 Avatar asked Mar 01 '16 19:03

cre8


1 Answers

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
like image 186
guru_007 Avatar answered Sep 17 '22 13:09

guru_007