如何获取24小时格式的amCalendar过滤器(Angular-Moment.js) [英] How to get amCalendar filter in 24hours format (Angular-Moment.js)
问题描述
我正在使用角矩,并且添加了矩函数:moment().add(7, 'h');
.
I am using angular-moment, and the moment add function: moment().add(7, 'h');
.
为了显示何时将完成批准.
In order to display when an approval will be done.
我有一张表,显示各种产品的批准估算.我正在使用amCalender
过滤器.例如,结果可能显示在今天晚上10点,等等.我希望时间改为24小时制(今天为22:00).
I have a table showing estimation for approval for various products. I am using amCalender
filter. The results may for example show today at 10pm etc. I want the time to be in 24 hours format instead (today at 22:00).
推荐答案
作为文档说, amCalendar
:
使用moment.js
calendar()
方法设置日期格式.
Format dates using moment.js
calendar()
method.
您可以使用 moment.updateLocale
自定义时刻calendar
输出.默认情况下,使用'[Today at] LT'
,'[Tomorrow at] LT'
等,而您需要使用'[Today at] HH:mm'
等.
You can customize moment calendar
output using moment.updateLocale
. By default moment use '[Today at] LT'
, '[Tomorrow at] LT'
etc, while in your case you need '[Today at] HH:mm'
etc.
这里有一个实际的工作示例:
Here a live working example:
angular.module('MyApp',['angularMoment'])
.run(function(){
moment.updateLocale('en', {
calendar : {
lastDay : '[Yesterday at] HH:mm',
sameDay : '[Today at] HH:mm',
nextDay : '[Tomorrow at] HH:mm',
lastWeek : '[last] dddd [at] HH:mm',
nextWeek : 'dddd [at] HH:mm',
sameElse : 'L'
}
});
})
.controller('AppCtrl', function($scope) {
$scope.message = {};
$scope.message.time = moment().add(7, 'h');
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.9/angular.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.1/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-moment/1.0.1/angular-moment.min.js"></script>
<div ng-app="MyApp" ng-controller="AppCtrl">
<span>{{message.time | amCalendar}}</span>
</div>
这篇关于如何获取24小时格式的amCalendar过滤器(Angular-Moment.js)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!