开发小工具
程序员文章站
2022-06-24 17:01:23
...
判断给定两个日期之间的间隔天数,是否超过某短时间
/**
* 判断两个时间之间是否超过给定天数
* @param: date1 { string|date }, yyyy-MM-dd 要判断的时间
* @param: date2 { string|date }, yyyy-MM-dd 要判断的时间
* @param: limit { number }, 给定的天数
* */
isOutPass (firstDate, secondDate, limit) {
if (!firstDate || !secondDate || !limit) {
return false
}
const firstDateTimestamp = new Date(firstDate.replace(/-/g, '/')).getTime()
const secondDateTimestamp = new Date(secondDate.replace(/-/g, '/')).getTime()
const limitTimestamp = limit * 24 * 60 * 60 * 1000
if (Math.abs(firstDateTimestamp - secondDateTimestamp) > limitTimestamp) {
return false
}
return true
}
获取当前日期和30天前的日期
getDefaultData () {
const date1 = new Date()
const date2 = new Date(date1)
// -30为30天前,+30可以获得30天后的日期
date2.setDate(date1.getDate() - 30)
// 30天前(月份判断是否小于10,小于10的前面+0)
const agoDay = `${date2.getFullYear()}-${date2.getMonth() + 1 < 10 ? `0${date2.getMonth() + 1}` : date2.getMonth() + 1}-${date2.getDate()}`
// 当前日期
const nowDay = `${date1.getFullYear()}-${date1.getMonth() + 1 < 10 ? `0${date1.getMonth() + 1}` : date1.getMonth() + 1}-${date1.getDate()}`
return [agoDay, nowDay]
},
推荐阅读
-
mysql 开发进阶篇系列 45 xtrabackup 安装,用户权限,配置
-
mysql 开发进阶篇系列 44 物理备份与恢复( 热备份xtrabackup 工具介绍)
-
【微信开发】01.数据库授权和连接,01数据库授权_PHP教程
-
Qt开发之鼠标事件
-
PHP微信公众开发笔记(六)_PHP教程
-
javascript - php 微信开发中图片长传的问题?
-
接口说明文档的生成(JavaDoc生成) 博客分类: 开发工具
-
Adding Unit Tests to an existing iOS project with Xcode 4 博客分类: 手机开发 iosunittest
-
让你的开发工具好看起来(eclipse 颜色主题) 博客分类: 开发工具
-
让你的开发工具好看起来(eclipse 颜色主题) 博客分类: 开发工具