function formatDate (val) {
// 格式化时间
let start = new Date(val)
let y = start.getFullYear()
let m = (start.getMonth() + 1) > 10 ? (start.getMonth() + 1) : '0' + (start.getMonth() + 1)
let d = start.getDate() > 10 ? start.getDate() : '0' + start.getDate()
return y + '-' + m + '-' + d
} function mistiming (sDate1, sDate2) {
// 计算开始和结束的时间差
let aDate, oDate1, oDate2, iDays
aDate = sDate1.split('-')
oDate1 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0])
aDate = sDate2.split('-')
oDate2 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0])
iDays = parseInt(Math.abs(oDate1 - oDate2) / 1000 / 60 / 60 / 24)
return iDays + 1
} function countDate (start, end) {
// 判断开始和结束之间的时间差是否在90天内
let days = mistiming(start, end)
let stateT = days > 90 ? Boolean(0) : Boolean(1)
return {
state: stateT,
day: days
}
}
function timeForMat (count) {
// 拼接时间
let time1 = new Date()
time1.setTime(time1.getTime() - (24 * 60 * 60 * 1000))
let Y1 = time1.getFullYear()
let M1 = ((time1.getMonth() + 1) > 10 ? (time1.getMonth() + 1) : '0' + (time1.getMonth() + 1))
let D1 = (time1.getDate() > 10 ? time1.getDate() : '0' + time1.getDate())
let timer1 = Y1 + '-' + M1 + '-' + D1 // 当前时间
let time2 = new Date()
time2.setTime(time2.getTime() - (24 * 60 * 60 * 1000 * count))
let Y2 = time2.getFullYear()
let M2 = ((time2.getMonth() + 1) > 10 ? (time2.getMonth() + 1) : '0' + (time2.getMonth() + 1))
let D2 = (time2.getDate() > 10 ? time2.getDate() : '0' + time2.getDate())
let timer2 = Y2 + '-' + M2 + '-' + D2 // 之前的7天或者30天
return {
t1: timer1,
t2: timer2
}
} function yesterday (start, end) {
// 校验是不是选择的昨天
let timer = timeForMat(1)
return timer
} function sevenDays () {
// 获取最近7天
let timer = timeForMat(7)
return timer
} function thirtyDays () {
// 获取最近30天
let timer = timeForMat(30)
return timer
} export {
formatDate,
countDate, yesterday,
sevenDays,
thirtyDays
}

js获取昨天,最近7天,最近30天通用方法的更多相关文章

  1. js获取或判断任意数据类类型的通用方法(getDataType)和将NodeList转为数组(NodeListToArray)

    function getDataType(any){ /* (1) Object.prototype.toString.call 方法判断类型: 优点:通用,返回"[object Strin ...

  2. Js获取后台集合List的值和下标的方法

    Js获取后台集合List的值和下标的方法 转载自:http://blog.csdn.net/XiaoKanZheShiJie/article/details/47280449 首先用的是struts2 ...

  3. js获取昨天日期

    刚刚js做项目,遇到需要获取昨天日期的问题,网上找了下答案,感觉网上的答案都不太严谨,自己写了个,凑合能用吧,忘大神们抛砖指教. <script type="text/javascri ...

  4. js获取昨天今天和明天

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/UP19910522/article/details/30028299 <html> &l ...

  5. JS获取昨天/今天/今年第一天的方法

    talk is cheap,show me the code! //获取昨天 var day1 = new Date(); day1.setTime(day1.getTime()-24*60*60*1 ...

  6. js获取上一页、当前页及域名url方法,JS反回上一页的方法

    <html> <head> <title>js获取上一页url,js获取前一页地址,javascripts获取上一页url,javascript获取前一页地址< ...

  7. Date——js 获取当前日期到之后一个月30天的日期区间

    var dateList = []; let startDate = new Date(); let endDate = new Date(); endDate.setDate(startDate.g ...

  8. js 获取昨天,今天,本周,上周,季度等时间范围(封装的js)

    (function ($, ht) { "use strict"; $.extend(ht, { clickTimeRange:function(){ //点击重置按钮,时间文本框 ...

  9. js获取昨天/上周/上个月开始和结束的时间戳,可以设置时分秒 js obtain start and end timestamp of yesterday/last week/last month, with set of hour/minute/second

    //obtain timestamp of last week var now=new Date() var nowDayOfWeek = now.getDay(); //今天本周的第几天 var n ...

随机推荐

  1. Flask的配置文件 与 session

    配置文件 flask中的配置文件是一个flask.config.Config对象(继承字典) 默认配置为: { 'DEBUG': get_debug_flag(default=False), 是否开启 ...

  2. POJ1228 Grandpa's Estate 稳定凸包

    POJ1228 转自http://www.cnblogs.com/xdruid/archive/2012/06/20/2555536.html   这道题算是很好的一道凸包的题吧,做完后会加深对凸包的 ...

  3. gitweb

    1. 简介 Gitweb提供了git版本库的图形化web浏览功能.可以到网站http://git.kernel.org/体验下效果,如下图所示. Gitweb界面 它既可以通过配置架设于web服务器上 ...

  4. ASP.NET给前端动态添加修改 CSS样式JS 标题 关键字(转载)

    原文地址:http://www.cnblogs.com/xbhp/p/6392225.html 有很多网站读者能换自己喜欢的样式,还有一些网站想多站点共享后端代码而只动前段样式,可以采用动态替换CSS ...

  5. P1266 速度限制(分层图spfa)

    P1266 速度限制 题目描述 在这个繁忙的社会中,我们往往不再去选择最短的道路,而是选择最快的路线.开车时每条道路的限速成为最关键的问题.不幸的是,有一些限速的标志丢失了,因此你无法得知应该开多快. ...

  6. 微信扫码下载APK遮罩提示示例

    由于微信的限制,应用文件在内置浏览器中下载全部被屏蔽掉,造成很多人用微信扫描二维码下载时,界面显示一片空白,容易误导以为在下载呢.按照当前主流习惯,做一个提示用户在浏览器中打开下载的遮罩.网上很多现成 ...

  7. [洛谷3930]SAC E#1 - 一道大水题 Knight

    Description 他们经常在一起玩一个游戏,不,不是星际争霸,是国际象棋.毒奶色觉得F91是一只鸡.他在一个n×n的棋盘上用黑色的城堡(车).骑士(马).主教(象).皇后(副).国王(帅).士兵 ...

  8. ACM_递推题目系列之一涂色问题(递推dp)

    递推题目系列之一涂色问题 Time Limit: 2000/1000ms (Java/Others) Problem Description: 有排成一行的n个方格,用红(Red).粉(Pink).绿 ...

  9. tablespace monitor shell for windows

    1. #! /bin/ksh #set -x SID=$1 ORACLE_SID=stat10gORACLE_HOME=/oracle10g/product/10.2PATH=$PATH:/usr/b ...

  10. [译]curl_multi_info_read

    curl_multi_info_read - read multi stack informationals读取multi stack中的信息 SYNOPSIS#include <curl/cu ...