1、 第一种格式转化。例如:“date = Tue Apr 04 2017 00:00:00 GMT+0800 (中国标准时间) ” 转换成 “2017-5-31 0:0:0”
实现方式为:
return date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate() + ' ' + date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds();
2. 自定义函数
函数调用:
format($scope.completiontime ,'yyyy-MM-dd');
function format(time, format){ var t = new Date(time); var tf = function(i){return (i < 10 ? "0" :"") + i}; return format.replace(/yyyy|MM|dd|HH|mm|ss/g, function(a){ switch(a){ case 'yyyy': return tf(t.getFullYear()); break; case 'MM': return tf(t.getMonth() + 1); break; case 'mm': return tf(t.getMinutes()); break; case 'dd': return tf(t.getDate()); break; case 'HH': return tf(t.getHours()); break; case 'ss': return tf(t.getSeconds()); break; } }) }