
判断是否距离到期时间9个月以内
给定一个到期时间,我们需要判断如果当前年份与到期时间年份一致,且距离到期月份还有 9 个月,则显示 true,否则显示 false。以下是如何编写此代码:
const isDistance9 = end => {
const d = new Date(end);
const now = new Date();
const difMonth = d.getMonth() - now.getMonth();
return (
now.getFullYear() == d.getFullYear() &&
difMonth <= 9 &&
difMonth >= 0
);
};










