Datepicker selects wrong date when using ISO 8601
When entering in a date in ISO 8601 format (yyyy-MM-dd), the calendar selects the entered date minus 1. So 2000-11-30 actually selects 2000-11-29.

I guess that you are using AngularJS 1.0.x which had a bug where dates were parsed in the UTC time-zone instead being interpreted in the local time zone. Hard to say more without a reproduce scenario in http://plnkr.co/
Sorry, that's a good point. I'm using AngularJS 1.0.8 because up until a few days ago it was the latest stable release. However, the screenshot above is actually from The AngularUI Bootstrap site itself - http://angular-ui.github.io/bootstrap/#/datepicker - which is also using 1.0.8, so perhaps that needs to be updated.
Still have this issue with angular 1.2 and angular-bootstrap 0.10.0. I select 3rd of February and the model contains 4th and so forth. And I can only reproduce if I set San Francisco (Pacific CA-USA) time, not Europe time.
I'm not sure if this issue is related with angular or bootstrap, but I solved just using the same format date in both sides.
Server:
def as_json(options = {})
{
id: model.id,
date: model.date.strftime("%d-%m-%Y")
}
end
Client
<input type="text" datepicker-popup="dd-MM-yyyy" ng-model="model.date" class="form-control" datepicker-options="dateOptions" show-weeks='false' is-open="opened" min="minDate" max="'2015-06-22'" date-disabled="disabled(date, mode)" close-text="Close" />
Regards!
Have the same problem when the date is set to dd.MM.yyyy. Angularjs version is 1.2 and angular-ui is version 0.10. This only happens when I enter the date manually.
Maybe this has something to do with the timezone I'm in?
We solved this problem by cutting off timezone information when we provide the date to the date picker. Example:
- server sends 28th of February 2014 15:05 GMT+2
- client is on PST timezone
- on client side we parse this date and instantiante: new Date(2014, 1, 28) // mind the "1" as February, months start from 0. => this basically generates: 28th of February 2014 00:00 PST and provides this to the date picker - some sort of "local equivalent"
Alternatively you could use moment.js to convert to this "local equivalent" if you don't want to do'it manually.
@dragosrususv can you provide some more detail in your fix? Where in the code did you cut off the timezone data?
On 17.03.2014 15:49, Dan Barrett wrote:
@dragosrususv https://github.com/dragosrususv can you provide some more detail in your fix? Where in the code did you cut off the timezone data?
Reply to this email directly or view it on GitHub https://github.com/angular-ui/bootstrap/issues/1278#issuecomment-37823776.
I fixed it eventually on the server side. I am using ASP.Net Web Api for the server side code. There, upon receiving the json date, I simply convert it to local time: var newValue = ((DateTime)value).ToLocalTime();
@thoughtpunch : There are 2 options:
- you cut-off time* information on server side and UI receives "2014-03-18" - instantiate a date object like "new Date(2014, 2, 18)" will get you the proper input for the date picker component
- you cut-off time* information on client side; UI extracts year, month and day from that and instantiates a date object as the above
In any case, you can either do your own dateService to handle this, either use moment.js for the "local equivalent".
Hope it helps.
I was able to solve the problem by adding a Json Converter with the format yyyy-MM-ddTHH:mmZ as per the angular date filter
MVC WebApi:
static public void RegisterJsonConverters(HttpConfiguration config) { config.Formatters.JsonFormatter.SerializerSettings.Converters.Add( new IsoDateTimeConverter() { DateTimeFormat = "yyyy-MM-ddTHH:mmZ" }); }
Works for version 011.0
see my comment at: https://github.com/eternicode/bootstrap-datepicker/issues/308
my solution is to use a directive to fix the minus 1 issue, and also to format the view and model values:
app.directive('ngBootstrapFix',['$filter', function($filter) { return { require: 'ngModel', priority: 1, link: function($scope, $element, $attrs, ngModelCtrl) { ngModelCtrl.$parsers.push(function(viewValue) { viewValue = $filter('date')(viewValue, 'yyyy-MM-dd'); return viewValue; }); ngModelCtrl.$render = function() { var val = $filter('date')(ngModelCtrl.$viewValue, 'dd/MM/yyyy'); $element.val(val); }; } }; }]);
Fantastic! Thanks for the directive, this is perfect! I added one comment to my code: Usage: <input ng-bootstrap-fix="currentResource.date_validated" ...
And modified the $render $filter: var val = $filter('date')(ngModelCtrl.$viewValue, 'MMM dd, yyyy');