如何写精华回答,获更多曝光?
发布
如代码和log所示,date.getMonth() 比预期值少1。
export function dateToMMDDPadLinkAsc(num: number, pad: string, link: string, asc: boolean): string {
const date = numToDate(num)
const mm = numberTo2Pad(date.getMonth(), pad)
const dd = numberTo2Pad(date.getDate(), pad)
if (DEBUG) {
console.info(TAG_COM, 'dateToMMDDPadLinkAsc',
'num:', dateToShortStr(num),
'date:', date,
'getMonth:', date.getMonth(),
'getDate:', date.getDate(),
)
}
return asc ? `${mm}${link}${dd}` : `${dd}${link}${mm}`
}
export function numToDate(num: number) {
return new Date(num)
}
06-30 18:33:55.671 10860-10860 I CommonComponent dateToMMDDPadLinkAsc num: 06/30 18:33 date: Sun Jun 30 2024 18:33:55 GMT+0800 getMonth(): 5 getDate(): 30