admin管理员组文章数量:1356329
I use ui.boostrap for a datepicker,
I need to format the date like "yyyy/MM/dd" because that's how my RESTapi receives the args. Applying $filter in angular.
.filter:date
It seems that the problem was solved, however when I change the date in the datepicker, the format date changes to a format like 2014-01-30T00:58:43.000Z
how can I set default format date with this tool?
I use ui.boostrap for a datepicker,
http://plnkr.co/edit/GfOQmgW85U2aW3YbZO7T?p=preview
I need to format the date like "yyyy/MM/dd" because that's how my RESTapi receives the args. Applying $filter in angular.
http://docs.angularjs/api/ng.filter:date
It seems that the problem was solved, however when I change the date in the datepicker, the format date changes to a format like 2014-01-30T00:58:43.000Z
how can I set default format date with this tool?
Share Improve this question edited Jan 28, 2014 at 12:09 JSK NS 3,4462 gold badges28 silver badges42 bronze badges asked Jan 28, 2014 at 11:51 ezeedezeed 581 silver badge6 bronze badges 2-
Did you try
<pre>Selected date is: <em>{{dt | date:'yyyy/MM/dd' }}</em></pre>
? – MrUpsidown Commented Jan 28, 2014 at 12:02 - 1 Yes, that's a filter in the view, but I need to format the date before sending to the API (the value in the controller), the first time works great but then return to the default settings. I need change the default format date. – ezeed Commented Jan 28, 2014 at 13:06
1 Answer
Reset to default 7Since the date is a JS Date object, you'll have to convert it before sending. You can use the datefilter to parse manually before sending:
var datefilter = $filter('date'),
formattedDate = datefilter($scope.dt, 'yyyy/MM/dd');
See this plunk for an example: http://plnkr.co/edit/EJLDpEojoFnf5QfFt4o6?p=preview
Only alternative I know of, is creating a directive for the value and pushing a function to $parsers like in this example, but that's definitely not easy to bine with the datepicker directive.
I'd suggest to continue using the Date object in JS, and just convert the value before sending to your API.
本文标签: javascriptHow to set default format date with angular ui bootstrapStack Overflow
版权声明:本文标题:javascript - How to set default format date with angular ui bootstrap - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743993850a2572632.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论