Angular-UI One day is subtracted from the date in ui-date

Situation I want to use ui-date to set / change the date in my application. I use the latest stable versions of angular, angular -ui, jquery-ui, etc.

Problem Once a date is selected using the datepicker, the date in my model will be equal to the selected date minus 1 day. It will also be sent to my server and stored in my database this way.

Plunker http://plnkr.co/edit/Ft14Wa?p=preview Initially, the date of input datepicker and the date in my model are the same. After choosing a date, they differ.

Question What happens (wr) to (g) here ???

+4
source share
4 answers

ui-date expects your model to be the actual date object. In your case, this is a string. If you look at the console, you will see that angularUI actually informs you about this. Then he advises adding an additional ui-date-format tag with the specified date format with which your date string will be parsed into a date object.

In short, you need to configure your input as follows:

<input ui-date="{dateFormat: 'yy-mm-dd'}" ui-date-format="yy-mm-dd" ng-model="customer.contract_end_date"></input> 

Working plunker .

+9
source

this solves my problem. angularjs uses the default time zone, which takes into account hourly time. setting the timezone option of the ng model for UTC to clear the time in hours ......

 ng-model-options="{timezone:'UTC'}" 
+3
source

The problem is that angular uses its default timezone when parsing the date selected on datepicker. To solve the problem, you can use the ng-model-options directive, which takes a time zone parameter.

 <input type="text" ng-model-options="{timezone:'UTC'}" ... > 
+2
source

I set the date format as dd-mm-yyyy as my requirement. then set the date type as a string.

 <input type="text" class="form-control col-xs-9" data-date-format="dd-MM-yyyy" data-autoclose="1" ng-model="modelName" date-type="string" bs-datepicker required> 
0
source

All Articles