📜  如何在日期对象之后获得 6 个月 - 无论代码示例

📅  最后修改于: 2022-03-11 14:59:38.946000             🧑  作者: Mango

代码示例1
const getDaysInMonth = (year, month) => new Date(year, month, 0).getDate()

const addMonths = (input, months) => {
  const date = new Date(input)
  date.setDate(1)
  date.setMonth(date.getMonth() + months)
  date.setDate(Math.min(input.getDate(), getDaysInMonth(date.getFullYear(), date.getMonth()+1)))
  return date
}