1、AngularJs的controller中格式:
var dateAsString = $filter('date')(item_date, "yyyy-MM-dd hh:mm:ss");
注意: controller需要注入$filter
2、 AngularJs的views中格式:
{{item_date | date:'yyyy-MM-dd hh:mm:ss'}}
3.时间戳转换
var timestamp = Date.parse(new Date());
timestamp = timestamp / 1000;
console.log("当前时间戳为:" + timestamp);
var olddate=new Date(parseInt(enddate) * 1000).toLocaleString().substr(0,18);
console.log("olddate:" + olddate);
4.内容
function getCurrenyDate(enddate){
var timestamp = Date.parse(new Date());
timestamp = timestamp / 1000;
console.log("当前时间戳为:" + timestamp);
if(enddate>timestamp)
{
var currenyDate = $filter('date')(new Date(), "yyyy-MM-dd hh:mm:ss");
var oldDate=new Date(parseInt(enddate) * 1000);
var oldDateString = $filter('date')(oldDate, "yyyy-MM-dd hh:mm:ss");
console.log("oldDateString:" + oldDateString);
console.log("currenyDate:" + currenyDate);
var date1 = Date.parse(oldDateString);
var date2 = Date.parse(currenyDate);
vm.currenyDate=(date1-date2);
console.log(vm.currenyDate);
}
else
{
vm.currenyDate="已到期";
}
return vm.currenyDate;
}