Angular-UI 从 ui-date 中的日期减去一天 [英] Angular-UI One day is subtracted from date in ui-date

查看:30
本文介绍了Angular-UI 从 ui-date 中的日期减去一天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

情况我想使用 ui-date 在我的应用程序中设置/编辑日期.我使用 angular、angular-ui、jquery-ui 等的最新稳定版本.

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.

问题使用日期选择器选择日期后,我模型中的日期将等于所选日期减去 1 天.它也会以这种方式发送到我的服务器并保存在我的数据库中.

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.

笨蛋http://plnkr.co/edit/Ft14Wa?p=preview最初日期选择器输入中的日期和我的模型中的日期相同.选择日期后,他们就不同了.

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.

问题这里发生了什么(wr)on(g)???

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

推荐答案

ui-date 希望你的模型是一个实际的日期对象.在你的情况下,它是一个字符串.如果您查看控制台,您会看到 angularUI 实际上会通知您.然后它会建议您添加额外的 ui-date-format 标签,指定日期格式,您的日期字符串将被解析为日期对象.

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>

工作plunker.

这篇关于Angular-UI 从 ui-date 中的日期减去一天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆