前三十天:
var now = new Date();
var prev = now.setDate( now.getDate() - 30 )
vm.sDate = comm.getFormatDate( new Date(prev) , '-', '00:00' );
getFormatDate: function (date, format, hm){ var res = '', y, m , d, hours, minute; function toDoubleTime(time){ var s, arr = [], ele, i, len, res = []; // 0 也不能忽略 if( typeof time == "undefined" ){ s = ''; }else{ s = time; } arr = (s+'').split(':'); if( arr.length > 1 ){ for(i=0, len=arr.length; i<len; i++ ){ ele = arr[i]; ele = ele.trim(); ele.length < 2 ? (ele = '0' + ele) : ele; res.push(ele); } return res.join(' : '); }else{ ele = s + ''; ele.length < 2 ? (ele = '0' + ele) : ele; return ele; } } y = date.getFullYear(); m = date.getMonth() + 1; d = date.getDate(); hours = date.getHours(); minute = date.getMinutes(); if( hm ){ hours = hm.split(':')[0] || ''; minute = hm.split(':')[1] || ''; } switch (format){ case '-': res = y + '-' + toDoubleTime(m) + '-' + toDoubleTime(d) + ' ' + toDoubleTime(hours) + ':' + toDoubleTime(minute); break; case '/': res = y + '/' + m + '/' + d + ' ' + hours + ':' + minute; break; case 'zh': res = y + '年' + m + '月' + d + '日 ' + hours + ':' + minute; break; } return res; }