I am new to angular js . I am trying to give some date format like Nov-24-2016
, but its not working at all . Below is my code.
我是棱角分明的新手。我试图给出一些类似Nov-24-2016的日期格式,但它根本不起作用。以下是我的代码。
{{ x.created | date:" MM-d-y" }}
Here I want this format Nov-24-2016
在这里,我想要这种格式11月24日至2016年
and x.created value = 2016-11-24 08:02:21
和x.created value = 2016-11-24 08:02:21
Any suggestion? Thank you
有什么建议吗?谢谢
5 个解决方案
#1
2
you can create a custom
你可以创建一个自定义
.filter('datetime', function($filter){
return function(input){
if(input == null){ return ""; }
var _date = $filter('date')(new Date(input),'MM-dd-yyyy');
return _date.toUpperCase();
};
});
{{ x.created | datetime }}
#2
2
Have a look at the documentation: https://docs.angularjs.org/api/ng/filter/date
请查看文档:https://docs.angularjs.org/api/ng/filter/date
x.created must be either a Date object or a timestring with milliseconds since UTC epoch.
x.created必须是Date对象或自UTC时期以来毫秒的时间字符串。
So either create a manual filter for it or parse your datestring to a Date object.
因此要么为它创建一个手动过滤器,要么将datetring解析为Date对象。
#3
1
To use date
Pipe x.created
must be date object or a number (milliseconds since UTC epoch) or an ISO string as per DatePipe
要使用日期管道x.created必须是日期对象或数字(自UTC纪元以来的毫秒数)或根据DatePipe的ISO字符串
#4
0
{{ x.created | date: "MMM-d-y" }}
renders to Nov-24-2016
{{x.created |日期:“MMM-d-y”}}呈现给Nov-24-2016
Btw: 2016-11-24 08:02:21
seems not to be a valid ISO string, https://www.w3.org/TR/NOTE-datetime. You could check this.
顺便说一句:2016-11-24 08:02:21似乎不是一个有效的ISO字符串,https://www.w3.org/TR/NOTE-datetime。你可以检查一下。
#5
0
I had similar problem. It's fix after 2 steps, change document encoding to utf-8 without BOM and rewrite manually data of time. Like this - date: 2013-12-02T17:57:28.556094Z
我有类似的问题。经过2个步骤后修复,将文件编码更改为没有BOM的utf-8,并手动重写时间数据。喜欢这个 - 日期:2013-12-02T17:57:28.556094Z
#1
2
you can create a custom
你可以创建一个自定义
.filter('datetime', function($filter){
return function(input){
if(input == null){ return ""; }
var _date = $filter('date')(new Date(input),'MM-dd-yyyy');
return _date.toUpperCase();
};
});
{{ x.created | datetime }}
#2
2
Have a look at the documentation: https://docs.angularjs.org/api/ng/filter/date
请查看文档:https://docs.angularjs.org/api/ng/filter/date
x.created must be either a Date object or a timestring with milliseconds since UTC epoch.
x.created必须是Date对象或自UTC时期以来毫秒的时间字符串。
So either create a manual filter for it or parse your datestring to a Date object.
因此要么为它创建一个手动过滤器,要么将datetring解析为Date对象。
#3
1
To use date
Pipe x.created
must be date object or a number (milliseconds since UTC epoch) or an ISO string as per DatePipe
要使用日期管道x.created必须是日期对象或数字(自UTC纪元以来的毫秒数)或根据DatePipe的ISO字符串
#4
0
{{ x.created | date: "MMM-d-y" }}
renders to Nov-24-2016
{{x.created |日期:“MMM-d-y”}}呈现给Nov-24-2016
Btw: 2016-11-24 08:02:21
seems not to be a valid ISO string, https://www.w3.org/TR/NOTE-datetime. You could check this.
顺便说一句:2016-11-24 08:02:21似乎不是一个有效的ISO字符串,https://www.w3.org/TR/NOTE-datetime。你可以检查一下。
#5
0
I had similar problem. It's fix after 2 steps, change document encoding to utf-8 without BOM and rewrite manually data of time. Like this - date: 2013-12-02T17:57:28.556094Z
我有类似的问题。经过2个步骤后修复,将文件编码更改为没有BOM的utf-8,并手动重写时间数据。喜欢这个 - 日期:2013-12-02T17:57:28.556094Z