export function getCurrentTime() { var date = new Date() var month = date.getMonth() + 1 var strDate = date.getDate() if (month >= 1 && month <= 9) { month = '0' + month } if (strDate >= 0 && strDate <= 9) { strDate = '0' + strDate } var hours = date.getHours() if (hours >= 0 && hours <= 9) { if (hours === 0) { hours = '00' } else { hours = '0' + hours } } var minutes = date.getMinutes() if (minutes >= 0 && minutes <= 9) { if (minutes === 0) { minutes = '00' } else { minutes = '0' + minutes } } var seconds = date.getSeconds() if (seconds >= 0 && seconds <= 9) { if (seconds === 0) { seconds = '00' } else { seconds = '0' + seconds } } var currentdate = date.getFullYear() + '.' + month + '.' + strDate + ' ' + hours + ':' + minutes + ':' + seconds console.log(currentdate) // 2017.07.11 15:14:44 return currentdate } // 获取当前时间 export function getNow(type = 'day') { const date = new Date() let month = date.getMonth() + 1 let strDate = date.getDate() if (month >= 1 && month <= 9) { month = '0' + month } if (strDate >= 0 && strDate <= 9) { strDate = '0' + strDate } let hours = date.getHours() if (hours >= 0 && hours <= 9) { if (hours === 0) { hours = '00' } else { hours = '0' + hours } } let minutes = date.getMinutes() if (minutes >= 0 && minutes <= 9) { if (minutes === 0) { minutes = '00' } else { minutes = '0' + minutes } } let seconds = date.getSeconds() if (seconds >= 0 && seconds <= 9) { if (seconds === 0) { seconds = '00' } else { seconds = '0' + seconds } } // const currentdate = date.getFullYear() + '.' + month + '.' + strDate + ' ' + hours + ':' + minutes + ':' + seconds; if (type === 'day') { return date.getFullYear() + '-' + month + '-' + strDate } else if (type === 'time') { return date.getFullYear() + '-' + month + '-' + strDate + ' ' + hours + ':' + minutes + ':' + seconds } } // 获取当日时间 const _date = new Date() const year = _date.getFullYear() + '' const month = (_date.getMonth() + 1) + '' function format(v) { return v < 10 ? '0' + v : v } export function getFullYear() { return year } export function getToday() { return year + '-' + format(month) + '-' + _date.getDate() } export function getFullMonth() { var month = _date.getMonth() + 1 if (month >= 1 && month <= 9) { month = '0' + month } return month } export function getFullDay() { var strDate = _date.getDate() if (strDate >= 0 && strDate <= 9) { strDate = '0' + strDate } return strDate }