获取当前时间格式为“2018-09-01 18:03” current_time() { var date = new Date(); let year = date.getFullYear(); //获取完整的年份(4位) let month = date.getMonth() + 1; //获取当前月份(0-11,0代表1月) let day = date.getDate(); //获取当前日(1-31) let hours = date.getHours(); //获取当前小时数(0-23) let minutes = date.getMinutes(); //获取当前分钟数(0-59) if (hours < 10) { hours = '0' + hours //小时小于10变成09、08、07样式 } if (month < 10) { month = '0' + month //月小于10变成09、08、07样式 } if (day < 10) { day = '0' + day //天小于10变成09、08、07样式 } if (minutes < 10) { minutes = '0' + minutes //分钟小于10变成09、08、07样式 } console.log(year + '-' + month '-' + day + ' ' + hours + ':' + minutes) //打印的是年月日小时和分钟 return year + '-' month+ '-' day + ' ' + hours + ':' + minutes //return 出去的格式为 "2018-09-01 18:03" } 切勿白嫖 再用到当前时间时直接调用this.current_time()此方法即可!