获取默认的开始时间和结束时间

获取默认的开始时间和结束时间function getDefaultTi const date new Date 获取开始日期 const startDate new Date date getTime 6 24 60 60 1000 const startYear startDate

大家好,我是讯享网,很高兴认识大家。

function getDefaultTime() {

  const date = new Date()

  // 获取开始日期

  const startDate = new Date(date.getTime() - 6 * 24 * 60 * 60 * 1000)

  const startYear = startDate.getFullYear()

  let startMonth = startDate.getMonth() + 1

  startMonth = startMonth <= 9 ? '0' + startMonth : startMonth

  let startDay = startDate.getDate()

  startDay = startDay <= 9 ? '0' + startDay : startDay

  // 结束日期

  const year = date.getFullYear()


讯享网

  let month = date.getMonth() + 1

  let strDate = date.getDate()

  if (month >= 1 && month <= 9) {

    month = '0' + month

  }

  if (strDate >= 0 && strDate <= 9) {

    strDate = '0' + strDate

  }

  return [startYear + '-' + startMonth + '-' + startDay, year + '-' + month + '-' + strDate]

}

小讯
上一篇 2025-01-10 13:21
下一篇 2025-01-19 21:27

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/85722.html