本地化日期格式化:
({{ today | date:'medium' }})Aug 17, 2018 1:52:58 PM
({{ today | date:'short' }})8/17/18 1:52 PM
({{ today | date:'fullDate' }})Friday, August 17, 2018
({{ today | date:'longDate' }})August 17, 2018
({{ today | date:'mediumDate' }})Aug 17, 2018
({{ today | date:'shortDate' }})8/17/18
({{ today | date:'mediumTime' }})1:52:58 PM
({{ today | date:'shortTime' }})1:52 PM
年份格式化:
四位年份:({{ today | date:'yyyy' }})2018
两位年份:({{ today | date:'yy' }})18
一位年份:({{ today | date:'y' }})2018
月份格式化:
英文月份:({{ today | date:'MMMM' }})August
英文月份简写:({{ today | date:'MMM' }})Aug
两位数字月份:({{ today | date:'MM' }})08
一年中的第几个月份:({{ today | date:'M' }})8
日期格式化:
数字日期:({{ today | date:'dd' }})17
一个月中的第几天:({{ today | date:'d' }})17
英文星期:({{ today | date:'EEEE' }})Friday
英文星期简写:({{ today | date:'EEE' }})Fri
小时格式化:
24小时制数字小时:({{ today | date:'HH' }})13
一天中的第几个小时:({{ today | date:'H' }})13
12小时制数字小时:({{ today | date:'hh' }})01
上午或下午的第几个小时:({{ today | date:'h' }})1
分钟格式化:
数字分钟数:({{ today | date:'mm' }})52
一个小时中的第几分钟:({{ today | date:'m' }})52
秒数格式化:
数字秒数:({{ today | date:'ss' }})58
一分钟中内的第几秒:({{ today | date:'s' }})58
毫秒数格式化:
毫秒数:({{ today | date:'sss' }})752、
字符格式化:
上下午标识:({{ today | date:'a' }})PM
四位时区标识:({{ today | date:'Z' }})+0800
自定义日期格式化:
年月日:({{ today | date:'yyyy-MM-dd' }})2018-08-17
时分秒:({{ today | date:'HH:mm:ss.sss' }})13:52:58.752
var myApp = angular.module('myApp', []);
myApp.controller('MyController',['$scope', '$filter', function($scope, $filter) {
$scope.today = new Date();
// Js调用$filter实例:L
console.log('Js $filter log: ', $filter('date')($scope.today, 'yyyy-MM-dd'));
}]);