How to set default format date with angular ui bootstrap

你说的曾经没有我的故事 提交于 2019-12-22 10:54:06

问题


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.org/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?


回答1:


Since 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 combine 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.



来源:https://stackoverflow.com/questions/21404883/how-to-set-default-format-date-with-angular-ui-bootstrap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!