![](/img/trans.png)
[英]min Attribute for date input type not accepting variable value in javascript
[英]Want to initialise “min” attribute of input type=“date” in HTML5 having date value in specific date format
我有下面提到的特定日期格式的日期。
Date_received = Tue Apr 05 2016 00:00:00 GMT+0530 (India Standard Time)
我正在使用HTML5
输入type =“ date” datepicker获取此值。 我想初始化以下“ min”属性。
<input type="date" id="endDate" ng-model="user.endDate" min="" required />
我正在使用
var startDate = new Date(Date_received).toISOString().split('T')[0]; var myEl = angular.element( document.querySelector( '#endDate' ) ); myEl.attr('min',startDate);
但是this( new Date(Date_received).toISOString()
)设置实际日期前一天的startDate值。 即在此示例中,它设置startDate = 2016-04-04T18:30:00.000Z
它是相同的值,但是toISOString()输出您的UTC时区值。
http://www.timeanddate.com/worldclock/converted.html?iso=20160405T00&p1=54&p2=0
如果要输出与“ ISO”相同的格式,但要输出语言环境时区,则应查看以下解决方案:
使用Angular的$filter
服务。 将其注入您的controller
/ directive
JS:
scope.startDate = startDateReceivedFromBackend;
scope.minDate = $filter('date')(scope.startDate, "dd/MM/yyyy");
在此处查看不同的格式: https : //docs.angularjs.org/api/ng/filter/date
HTML:
<input type="date" id="endDate" ng-model="user.endDate" min="minDate" required />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.