format-utils.js
478 Bytes
function pad2(n) {
return String(n).padStart(2, '0')
}
/** 默认区间:当月 1 日 → 今天 */
export function getDefaultDateRange() {
const now = new Date()
const year = now.getFullYear()
const month = now.getMonth() + 1
const day = now.getDate()
return [`${year}-${pad2(month)}-01`, `${year}-${pad2(month)}-${pad2(day)}`]
}
export function dateToStatisticsMonth(dateStr) {
if (!dateStr) return ''
return String(dateStr).replace(/-/g, '').slice(0, 6)
}