如果当前年份跟到期时间年份一致,且离到期月份还有9个月,可以显示true,超出到期时间则显示false,代码应该怎么写?

自己定义一个到期时间,如果当前年份跟到期时间年份一致,且离到期月份还有9个月,可以显示true,超出到期时间则显示false,代码应该怎么写?

阅读 1.4k
1 个回答

你都能说出来了,转换成代码也不难吧

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
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题