关于时间转换-----angularjs

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Aaor_01/article/details/77920913

1、angular中我们自己设置的时间filter

//获取时间转换成指定样式的filter

//其他时间样式---->制定时间样式
app.filter('formatDatefilter', function() {
return function(input) {
var date = new Date(input);
Y = date.getFullYear() + '-';
M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
D = date.getDate() + ' ';
//formatDate = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
var formatDate = Y + M + D;
return formatDate;
}

});

2、对页面<input type='date' /> 输入的日期进行转换

/**
* 出生年月时间
*/
var birthdayTime = new Date($scope.birthday).getTime();// 将标准时间转为时间戳
console.log(birthdayTime);
var birthdayDate = new Date(birthdayTime);
Y = birthdayDate.getFullYear() + '-';
M = (birthdayDate.getMonth() + 1 < 10 ? '0' + (birthdayDate.getMonth() + 1) : birthdayDate.getMonth() + 1) + '-';
D = birthdayDate.getDate() + ' ';
var birthdayParam = Y + M + D;
console.log(birthdayParam); 

猜你喜欢

转载自blog.csdn.net/Aaor_01/article/details/77920913