JS获取本周、本季度、本月、上月的开始日期、结束日期
- /**
- * 获取本周、本季度、本月、上月的开始日期、结束日期
- */
- var now = new Date(); //当前日期
- var nowDayOfWeek = now.getDay(); //今天本周的第几天
- var nowDay = now.getDate(); //当前日
- var nowMonth = now.getMonth(); //当前月
- var nowYear = now.getYear(); //当前年
- nowYear += (nowYear < 2000) ? 1900 : 0; //
- var lastMonthDate = new Date(); //上月日期
- lastMonthDate.setDate(1);
- lastMonthDate.setMonth(lastMonthDate.getMonth()-1);
- var lastYear = lastMonthDate.getYear();
- var lastMonth = lastMonthDate.getMonth();
- //格式化日期:yyyy-MM-dd
- function formatDate(date) {
- var myyear = date.getFullYear();
- var mymonth = date.getMonth()+1;
- var myweekday = date.getDate();
- if(mymonth < 10){
- mymonth = "0" + mymonth;
- }
- if(myweekday < 10){
- myweekday = "0" + myweekday;
- }
- return (myyear+"-"+mymonth + "-" + myweekday);
- }
- //获得某月的天数
- function getMonthDays(myMonth){
- var monthStartDate = new Date(nowYear, myMonth, 1);
- var monthEndDate = new Date(nowYear, myMonth + 1, 1);
- var days = (monthEndDate - monthStartDate)/(1000 * 60 * 60 * 24);
- return days;
- }
- //获得本季度的开始月份
- function getQuarterStartMonth(){
- var quarterStartMonth = 0;
- if(nowMonth<3){
- quarterStartMonth = 0;
- }
- if(2<nowMonth && nowMonth<6){
- quarterStartMonth = 3;
- }
- if(5<nowMonth && nowMonth<9){
- quarterStartMonth = 6;
- }
- if(nowMonth>8){
- quarterStartMonth = 9;
- }
- return quarterStartMonth;
- }
- //获得本周的开始日期
- function getWeekStartDate() {
- var weekStartDate = new Date(nowYear, nowMonth, nowDay - nowDayOfWeek);
- return formatDate(weekStartDate);
- }
- //获得本周的结束日期
- function getWeekEndDate() {
- var weekEndDate = new Date(nowYear, nowMonth, nowDay + (6 - nowDayOfWeek));
- return formatDate(weekEndDate);
- }
- //获得本月的开始日期
- function getMonthStartDate(){
- var monthStartDate = new Date(nowYear, nowMonth, 1);
- return formatDate(monthStartDate);
- }
- //获得本月的结束日期
- function getMonthEndDate(){
- var monthEndDate = new Date(nowYear, nowMonth, getMonthDays(nowMonth));
- return formatDate(monthEndDate);
- }
- //获得上月开始时间
- function getLastMonthStartDate(){
- var lastMonthStartDate = new Date(nowYear, lastMonth, 1);
- return formatDate(lastMonthStartDate);
- }
- //获得上月结束时间
- function getLastMonthEndDate(){
- var lastMonthEndDate = new Date(nowYear, lastMonth, getMonthDays(lastMonth));
- return formatDate(lastMonthEndDate);
- }
- //获得本季度的开始日期
- function getQuarterStartDate(){
- var quarterStartDate = new Date(nowYear, getQuarterStartMonth(), 1);
- return formatDate(quarterStartDate);
- }
- //或的本季度的结束日期
- function getQuarterEndDate(){
- var quarterEndMonth = getQuarterStartMonth() + 2;
- var quarterStartDate = new Date(nowYear, quarterEndMonth, getMonthDays(quarterEndMonth));
- return formatDate(quarterStartDate);
- }
JS获取本周、本季度、本月、上月的开始日期、结束日期的更多相关文章
- js 获取 本周、上周、本月、上月、本季度、上季度的开始结束日期
js 获取 本周.上周.本月.上月.本季度.上季度的开始结束日期 /** * 获取本周.本季度.本月.上月的开始日期.结束日期 */ var now = new Date(); //当前日期 va ...
- JS获取本周、本季度、本月、上月、本年的开始日期、结束日期
/** * 获取本周.本季度.本月.上月的开始日期.结束日期 */ var now = new Date(); //当前日期 var nowDayOfWeek = now.getDay(); //今 ...
- php 获取今日、昨日、本周,上周、本月,上月,季度的起始时间戳和结束时间戳的方法
php 获取今日.昨日.上周.本月的起始时间戳和结束时间戳的方法,主要使用到了 php 的时间函数 mktime.下面首先还是直奔主题以示例说明如何使用 mktime 获取今日.昨日.上周.本月的起始 ...
- moment.js获取本周本月本年的开始日期和结束日期
//获取本日 const startDate = moment().format('YYYY-MM-DD'); const startDate = moment().format('YYYY-MM-D ...
- js获取本周、上周的开始结束时间
这两天在做一个报表体统,其中涉及到了一个根据本周,上周,本月,上月的时间来进行查询的问题,在这个我就教一下大家怎么实现,大家如果有更好的实现方法的,我也希望大家能说出来,我们交流交流. 首先呢,我写了 ...
- js获取本周日期
JS获取到本周的日期 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> &l ...
- js获得本季度的开始日期 结束日期
var now = new Date(); //当前日期var nowMonth = now.getMonth()+1; //当前月var nowYear = now.getFullYear(); / ...
- PHP获取一年有多少周和每周开始和结束日期
/*PHP获取当前日期是第几周和本周开始日期和本周结束日期*/ //$now = '2018-11-13';周二 public function getNowTimeInfo($now) { $str ...
- JS 获取 本周、本月、本季度、本年、上月、上周、上季度、去年
工具类定义: /** * 日期范围工具类 */ var dateRangeUtil = (function () { /*** * 获得当前时间 */ this.getCurrentDate = fu ...
随机推荐
- jquery插入,复制、替换和删除节点
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/stri ...
- 基于vue2.0实现仿百度前端分页效果(一)
前言 最近在接手一个后台管理项目的时候,由于之前是使用jquery+bootstrap做的,后端使用php yii框架,前后端耦合在一起,所以接手过来之后通过vue进行改造,但依然继续使用的boots ...
- 深入浅出 JVM GC(4)常用 GC 参数介绍
# 前言 从前面的3篇文章中,我们分析了5个垃圾收集器,还有一些 GC 的算法,那么,在 GC 调优中,我们肯定会先判断哪里出现的问题,然后再根据出现的问题进行调优,而调优的手段就是 JVM 提供给我 ...
- C#中的Action和Func和Predicate
一.[action<>]指定那些只有输入参数,没有返回值的委托 用了Action之后呢: 就是相当于省去了定义委托的步骤了. 演示代码: using System; using Syste ...
- windows 安装 keras
pip install keras 报错了,看报错信息是卡在scipy上了,查了一下 https://stackoverflow.com/questions/42240720/python-scipy ...
- CentOS7日期时间设置方法以及时间基本概念介绍
在CentOS 6版本,时间设置有date.hwclock命令,从CentOS 7开始,使用了一个新的命令timedatectl. 一.基本概念 1.1 GMT.UTC.CST.DST 时间 (1) ...
- VB.NET网络是否联通Function
''' <summary> ''' IP Ping ''' </summary> ''' <param name="strIpOrDName& ...
- ASP.NET Identity 二 (转载)
来源:http://www.cnblogs.com/r01cn/p/5180892.html#undefined 推荐看原文,这里转载是怕好文章消失了. 注:本文是[ASP.NET Identity系 ...
- Hadoop小知识点总结1
1.数据仓库warehouse一般不做更改,只做查询 2.OLTP:联机事务处理,比如:转账 OLAP:联机分析处理,比如:只做查询 3.hadoop的思想来源: GFS (Google的文件系统)即 ...
- 精选20道Java代码笔试题
1.运算符优先级问题,下面代码的结果是多少? public class Test { public static void main(String[] args) { int k = 0; int r ...