如何设置默认格式日期的角度引导用户界面 [英] How to set default format date with angular ui bootstrap

查看:175
本文介绍了如何设置默认格式日期的角度引导用户界面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用ui.boostrap的日期选择器,

I use ui.boostrap for a datepicker,

http://plnkr.co/edit/GfOQmgW85U2aW3YbZO7T?p=$p$ PVIEW

我需要的格式,如YYYY / MM / DD的日期,因为这是我的RESTAPI如何接收ARGS。
应用$过滤器的角度。

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

看来,问题解决了,但是当我更改日期在日期选择器,格式日期更改为一种格式如 2014-01-30T00:58:43.000Z

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?

推荐答案

由于日期是JS Date对象,你必须在发送之前将其转换。您可以使用datefilter在发送前手动解析:

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');

为例参见本普拉克:<一href=\"http://plnkr.co/edit/EJLDpEojoFnf5QfFt4o6?p=$p$pview\">http://plnkr.co/edit/EJLDpEojoFnf5QfFt4o6?p=$p$pview

唯一的选择,我知道,是创造价值的指令,并在这个例子的,但是这绝对不是简单的日期选择器指令结合起来。

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.

我建议继续使用JS Date对象,只是发送给您的API之前换算的数值。

I'd suggest to continue using the Date object in JS, and just convert the value before sending to your API.

这篇关于如何设置默认格式日期的角度引导用户界面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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