//按特定格式生成现在的时间 vm.getNow = function(days){ /** * days:获取当前天的之前之后的第days天日期 * 示例:获取当天的,vm.getNow(0) * 特殊的天没有考虑,31日,2月等 * 获取今天时间 * 格式:2018-07-09 00:00:00 */ let nowDate = new Date().toLocaleDateString(); let nowTime = new Date().toLocaleTimeString(); let nowDateArr = nowDate.split('/'); if(parseInt(nowDateArr[1]) < 10){ nowDateArr[1] = '0'+ nowDateArr[1] } nowDateArr[2] = parseInt(nowDateArr[2]) + days; if(parseInt(nowDateArr[2]) < 10){ nowDateArr[2] = '0'+ nowDateArr[2] } nowDate = nowDateArr.join('-'); if(nowTime.indexOf('下午') > -1){ nowTime = nowTime.slice(2); let nowTimeArr = nowTime.split(':'); nowTimeArr[0] = parseInt(nowTimeArr[0]) + 12; nowTime = nowTimeArr.join(':'); }else if(nowTime.indexOf('上午') > -1){ nowTime = nowTime.slice(2); } return nowDate + ' ' + nowTime; }