angular 过滤器(日期转换,时间转换,数据转换等)
(function() {
angular.module('myApp')
.filter('is_null', function() {
return function(input) {
return input || '/';
}
})
//向下取整
.filter('star', function() {
return function(input) {
return Math.floor(input) || 0;
}
})
//向上取整
.filter('unstar', function() {
return function(input) {
return 5 - Math.ceil(input) || 0;
}
})
//百分比
.filter('percent', function() {
return function(input) {
return (input * 100).toFixed(2) || 0;
}
})
// 毫秒转天时分
.filter('formatDuring', function() {
return function(mss) {
var days = parseInt(mss / (1000 * 60 * 60 * 24));
var hours = parseInt((mss % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = parseInt((mss % (1000 * 60 * 60)) / (1000 * 60));
var seconds = (mss % (1000 * 60)) / 1000;
return days + " 天 " + hours + " 小时 " + minutes + " 分钟 " + seconds + " 秒 ";
}
})
//时间戳转换
.filter('getWeek', function() {
return function(input) {
var date = new Date(input * 1000);
var week = date.getDay();
switch (week) {
case 0:
return "星期天";
break;
case 1:
return "星期一";
break;
case 2:
return "星期二";
break;
case 3:
return "星期三";
break;
case 4:
return "星期四";
break;
case 5:
return "星期五";
break;
case 6:
return "星期六";
break;
}
}
})
.filter('snapshot', function() {
return function(input) {
input = input || '';
var output = input.split('|')[0];
return output;
}
})
})();