Comparing version 1.0.6 to 1.0.7
const date = { | ||
dateFormat: (d, fmt) => { // format(new Date(), 'MM月dd日 hh:mm') | ||
dateFormat (d, fmt) { // format(new Date(), 'YYYY年MM月DD日 hh:mm:ss') | ||
if (!d || !fmt) { | ||
throw new Error('lack date or format') | ||
} | ||
if (typeof(d) === 'string') { | ||
d = new Date(d) | ||
} | ||
const o = { | ||
'M+': d.getMonth() + 1, // 月份 | ||
'd+': d.getDate(), // 日 | ||
'D+': d.getDate(), // 日 | ||
'h+': d.getHours(), // 小时 | ||
'm+': d.getMinutes(), // 分 | ||
's+': d.getSeconds(), // 秒 | ||
'q+': Math.floor((d.getMonth() + 3) / 3), // 季度 | ||
'Q+': Math.floor((d.getMonth() + 3) / 3), // 季度 | ||
'S': d.getMilliseconds() // 毫秒 | ||
} | ||
if (/(y+)/.test(fmt)) { | ||
if (/(Y+)/.test(fmt)) { | ||
fmt = fmt.replace(RegExp.$1, (d.getFullYear() + '').substr(4 - RegExp.$1.length)) | ||
@@ -25,4 +31,31 @@ } | ||
} | ||
// TodayFormat (date) { | ||
// if (!date) { | ||
// throw new Error('lack date') | ||
// } | ||
// const fmt = 'YYYY-MM-DD' | ||
// const cur = new Date() // 当前年月日 | ||
// const curYear = cur.getFullYear() | ||
// const curMonth = cur.getMonth() + 1 | ||
// const curDay = cur.getDate() | ||
// const next = new Date(`${curYear}/${curMonth}/${curDay + 1}`) // 明天年月日 | ||
// const param = new Date(date) // 传进来的年月日 | ||
// const paramDay = new Date().getDate() | ||
// const nowDate = this.dateFormat(cur, fmt) | ||
// const nextDate = this.dateFormat(next, fmt) | ||
// const paramDate = this.dateFormat(param, fmt) | ||
// if (nowDate == nextDate) { | ||
// return '今天' + this.dateFormat(paramDate, 'hh:mm') | ||
// } else if (paramDay === curDay) { | ||
// return '明天' + this.dateFormat(paramDate, 'hh:mm') | ||
// } else { | ||
// return this.dateFormat(paramDate, 'MM月DD日 hh:mm') | ||
// } | ||
// } | ||
} | ||
export default date |
{ | ||
"name": "fe-utils", | ||
"version": "1.0.6", | ||
"version": "1.0.7", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "fe-utils.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31831
862