本文介绍了日期格式化AngularJS仅显示日期和月份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我为Angular完成了新手。所以我有created_at的日期值。这是
I am completed newbie to Angular. So I have date value for created_at. which is
2008-04-25 00:00:00
我希望每个月只能用英语获得同一天。我已经尝试了以下方法来制作样本以获得单独的年份。但过滤器似乎不起作用。我做错了什么?
I want to get only the day similarly month in English. I have tried the following to make sample to get Year alone. But the filter not seems to be working. What am I doing wrong?
<h2>Recent Study</h2>
<ul ng-repeat="x in names">
<li>
<div class="date">
<span class="day">{{ x.created_at | date : 'yyyy' }}</span>
<span class="month">Jul</span>
</div>
<p><a href="#">{{ x.study_description }}</a></p>
</li>
</ul>
推荐答案
您需要将日期转换为秒,并使用客户过滤器:
You need to convert the date to seconds, and use a custome filter:
app.filter('toSec', function($filter) {
return function(input) {
var result = new Date(input).getTime();
return result || '';
};
});
并在您的HTML中使用它,如下所示:
and use it in your HTML like this:
{{ '2008-04-25 00:00:00' | toSec | date:'EEEE'}}
结果:
Friday
Angular让您可以选择创建
Angular gives you the option to create a Custome Filter
这是一个有效的,使用客户过滤器实现您的需求。
Here's a working example that achieves what you need using a custome filter.
这篇关于日期格式化AngularJS仅显示日期和月份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!