js根据年月获取该月份的最后一天的日期字符串
const formatExpirationDate = (expirationDate) => {
const startYearMonth = expirationDate[0];
const endYearMonth = expirationDate[1];
const getEndOfMonth = (yearMonth) => {
const date = new Date(yearMonth);
date.setMonth(date.getMonth() + 1, 0);
return `${yearMonth}-${String(date.getDate()).padStart(2, '0')}`;
};
const startDate = getEndOfMonth(startYearMonth);
const endDate = getEndOfMonth(endYearMonth);
return [`${startDate}"`, `"${endDate}`];
};
const expirationDate = ["2024-08", "2024-09"];
const formattedDate = formatExpirationDate(expirationDate);
console.log(formattedDate);