一、date型转字符串:
$filter('date')(date, 'yyyyMM');
$filter('date')(time, 'HH:mm');
//在控制器中使用必须注入 $filter 模块
app.controller("demoCtrl", ["$scope", "$filter", function($scope, $filter){
$scope.dt1 = new Date();
}])
//控制器中使用
$scope.dt2 = $filter("date")($scope.dt1, "yyyy-MM-dd HH:mm:ss");
$scope.jobMonth = new Date($scope.jobMonth).format('yyyyMM').toString();
二、html文件中时间戳转date
1. <!-- 表达式中使用 -->
{{ dt1 | date:'yyyy-MM-dd HH:mm:ss' }}
2. 将 "时间戳" 转换为 "年月日" 的格式:
var da = 1402233166999;
da = new Date(da);
var year = da.getFullYear()+'年';
var month = da.getMonth()+1+'月';
var date = da.getDate()+'日';
console.log([year,month,date].join('-'));
运行如下:
三、获取当前系统时间
var dateTimeStr = new Date().format('yyyyMMddhhmmss');