Datepicker shows one day behind when using yyyy-MM-dd format

+1, can confirm.
I have the same issue, any solutions?
This is probably a time zone issue, try displaying model.toISOString() to see.
@awb You are right :+1: . I could solve this adding timezone with getTimezoneOffset() :)
So is this fixable on my end or is this a bug within the directive? I'm passing a date like "2014-09-10" and the datepicker dropdown is displaying 2014-09-09 but the input is correct.
I fixed it simply by converting all date strings (my backend returns ISO dates like 2014-09-10) into date objects in my controller.
This is how I fixed it. I added my timezone
var d = new Date('yourDate'); d.setMinutes( d.getMinutes() + d.getTimezoneOffset() );
'd' should be the correct date
Please put this in the docs - I just realized this as well (too late).
For yyyy-MM-dd it does not make sense, since the user is not entering a time value, so time is always T00:00:00 (+/- the gmt offset when converted to string)
This should now be addressed in 0.14.3.
There are still some timezone issues, i.e. the weakness in not being able to configure it, but one can set the timezone used by the datepicker via setting an initial model date value with the appropriate timezone.
This is still not fixed.
format: {
toDisplay: function(date, format, language)
{
console.log(date);
},
toValue: function(date, format, language)
{
return date;
}
}
This outputs:
Tue Sep 06 2016 20:00:00 GMT-0400
Today is the 7th!
I guess, I am experiencing the same issue right now, version 1.3.3
I'm experiencing this same issue, and I'm not even concerned with the time of day. I just want to be able to choose a day. Picker keeps picking the day before. Not a good outcome for me.
I ran into this yesterday and found the solution is to set the timezone option to utc and the date is no longer off by one. The syntax for doing that is here: https://github.com/angular-ui/bootstrap/issues/4837#issuecomment-203284205
Thanks Elijah. But that did not resolve the issue for me. I really wish they would fix this bug, rather than just close the many Issues that people raise which reference it.
If you'd like to hardcode a timezone, you could do what I did. As @charger513 mentioned, you can set the minutes along with the timezone offset -- but instead of determining your current timezone automatically, you could substitute the timezone offset with the amount of minutes - in my case, my local timezone was returning -660 (UTC-11). But I needed it to be 480 (UTC+08).
var d = new Date('yourDate');
d.setMinutes( d.getMinutes() + 480 );
I was then finally getting the output I wanted - as my PHP backend counterpart was aligned to the UTC+08 timezone.
Find your timezone minutes offset here: https://forbrains.co.uk/international_tools/earth_timezones
I have found a way. convert that date to string first. here is the code.
var SelectDate = $scope.GetFormattedDate(Date.parse($("#Date").datepicker("getDate")));
$scope.GetFormattedDate = function (CalDate) {
var re = /-?\d+/;
var WDate = CalDate.toString();
var m = re.exec(WDate);
var lastDate = new Date(parseInt(m[0]));
var mm = lastDate.getMonth() + 1;
var dd = lastDate.getDate();
var yyyy = lastDate.getFullYear();
var formattedDate = mm + '/' + dd + '/' + yyyy;
return formattedDate;
}
Now Pass SelectDate to your controller. bingo problem has been resolved :)
Can't believe this is still a bug..
I solved this issue by giving the Date field in Backend as Edm.DateTimeOffset (this will be a Timestamp field in ABAP) & converting the timestamp field to Date & Time by using function module - IB_CONVERT_FROM_TIMESTAMP.
if you are using moment, you can user the 'utc date'
moment.utc('23-12-2011')
This works for me
var DatePickerDate ='Thu Aug 09 2018 00:00:00 GMT+0100 (British Summer Time)';
var myDate = new Date(DatePickerDate).toISOString();
so myDate is now 2018-08-08T23:00:00.000Z