4

The situation I want to use ui-date to set/edit a date in my app. I use the latest stable versions of angular, angular-ui, jquery-ui etc.

The problem As soon as a date is selected using the datepicker the date in my model will equal the selected date minus 1 day. It will also get send to my server and saved in my database this way.

The plunker http://plnkr.co/edit/Ft14Wa?p=preview Initially the date in the datepicker input and the date in my model are the same. After picking a date they differ.

The question What is going (wr)on(g) here???

4

4 に答える 4

9

ui-dateは、モデルが実際の日付オブジェクトであることを想定しています。あなたの場合、それは文字列です。コンソールを見ると、angularUIが実際にそのことを通知していることがわかります。次に、日付文字列が日付オブジェクトに解析される、指定された日付形式のui-date-formatタグを追加することをお勧めします。

簡単に言うと、入力を次のように調整する必要があります。

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

働くプランカー

于 2013-03-05T15:20:13.560 に答える
4

this solves my problem. angularjs uses default timezone which considers hour time. seting timezone option of ng-model to UTC clear hour times......

ng-model-options="{timezone:'UTC'}"
于 2016-05-31T11:58:53.103 に答える
3

The problem is that angular is using its default timezone when parsing the date selected on the datepicker. To resolve the issue you can use the ng-model-options directive which accepts a "timezone" parameter.

<input type="text" ng-model-options="{timezone:'UTC'}" ... >
于 2016-04-26T11:16:02.397 に答える
0

I set date format as dd-mm-yyyy as my requirement. then set date-type as 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>
于 2016-12-07T05:34:47.517 に答える