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

后端 未结 4 1487
慢半拍i
慢半拍i 2020-12-10 19:56

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.

Th

相关标签:
4条回答
  • 2020-12-10 20:19

    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'}" ... >
    
    0 讨论(0)
  • 2020-12-10 20:34

    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>
    
    0 讨论(0)
  • 2020-12-10 20:36

    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'}"
    
    0 讨论(0)
  • 2020-12-10 20:41

    ui-date expects your model to be an actual date object. In your case it's a string. If you take a look at the console you'll see that angularUI actually informs you about that. Then it advises you to add additional ui-date-format tag with the specified date format with which your date string will be parsed into date object.

    Long story short, your need to adjust your input as this:

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

    Working plunker.

    0 讨论(0)
提交回复
热议问题