Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular Material Datepicker returns one day before the exact date

Im using angular material in my web site and when I send the date to my web api, it shows on day before the selected date. For an example if I put in 2016-01-03 then it will send 2016-01-02. How can I fix this issue. I haven't change any code form the original code provided in angular material web site the link to the code is below

https://material.angularjs.org/latest/demo/datepicker

like image 844
Tharindu Senanayake Avatar asked May 28 '16 04:05

Tharindu Senanayake


2 Answers

we recently faced the same , adjusting the value before posting like said in https://github.com/angular-ui/ui-date/issues/88

works fine. Hope its helpfull for some one.

 function adjustDateForTimeOffset(dateToAdjust) {
var offsetMs = dateToAdjust.getTimezoneOffset() * 60000;
return new Date(dateToAdjust.getTime() - offsetMs);
}
like image 118
Pradeep Avatar answered Sep 30 '22 13:09

Pradeep


Just try to use angular-moment as following.

var temp =(moment.utc(local.date));

I wrote a full article about this. FIX IN MD-DATEPICKER TO GET THESELECTED DATE

like image 28
nextt1 Avatar answered Sep 30 '22 15:09

nextt1