纸通宝小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

28 lines
884 B

function isEmpty(val) {
return typeof val === 'undefined' || val === '' || val === null
}
function formateDate(datetime) {
if (isEmpty(datetime)) {
return ''
}
var dayCode = 24 * 60 * 60 * 1000
datetime = datetime.replace(getRegExp('/\s/g', 'g'), '')
var date = getDate(datetime.trim())
var today = getDate()
var yestoday = getDate(getDate().getTime() - dayCode)
var week = ''
if (date.getFullYear() === today.getFullYear() && date.getMonth() === today.getMonth() && date.getDate() === today.getDate()) {
week = '今天 ' + datetime.substring(10)
} else if (date.getFullYear() === yestoday.getFullYear() && date.getMonth() === yestoday.getMonth() && date.getDate() === yestoday.getDate()) {
week = '昨天 ' + datetime.substring(10)
}
if (isEmpty(week)) {
return datetime
}
return week
}
module.exports = {
formateDate: formateDate
}