The judgment that the start time is less than the end time , Here's how to package the number , You can directly call :

	var data = new Date();
var year = data .getFullYear(); // Get full year (4 position )
var month = data .getMonth(); // Get current month (0-11,0 representative 1 month ) console.log(" Time ::"+formatDate(data));
console.log(getMonthStartDate(year,month));
console.log(getMonthEndDate(year,month));   // Format date :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);   
} 
// Get the start date of a month   
function getMonthStartDate(paraYear,paraMonth){  
  var monthStartDate = new Date(paraYear, paraMonth, 1);   
  return formatDate(monthStartDate);  
}  
  
// Get the end date of a month   
function getMonthEndDate(paraYear,paraMonth){
  var monthEndDate = new Date(paraYear,paraMonth, getMonthDays(paraYear,paraMonth));   
  return formatDate(monthEndDate);  
} 
// Get the number of days in a month   
function getMonthDays(paraYear,paraMonth){  
  var monthStartDate = new Date(paraYear, paraMonth, 1);   
  var monthEndDate = new Date(paraYear, paraMonth + 1, 1);   
  var  days  =  (monthEndDate  -  monthStartDate)/(1000  *  60  *  60  *  24);   
  return  days;   
}

   Here's more about

 Get this week 、 This quarter 、 This month, 、 The start date of last month 、 End date 
/**
* Get this week 、 This quarter 、 This month, 、 The start date of last month 、 End date
*/
var now = new Date(); // The current date
var nowDayOfWeek = now.getDay(); // Today is the third day of the week
var nowDay = now.getDate(); // Current day
var nowMonth = now.getMonth(); // The current month
var nowYear = now.getYear(); // The current year
nowYear += (nowYear < 2000) ? 1900 : 0; // var lastMonthDate = new Date(); // Last month's date
lastMonthDate.setDate(1);
lastMonthDate.setMonth(lastMonthDate.getMonth()-1);
var lastYear = lastMonthDate.getYear();
var lastMonth = lastMonthDate.getMonth(); // Format date :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);
} // Get the number of days in a month
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;
} // Get the start month of the quarter
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;
} // Get the start date of the week
function getWeekStartDate() {
var weekStartDate = new Date(nowYear, nowMonth, nowDay - nowDayOfWeek);
return formatDate(weekStartDate);
} // Get the end date of the week
function getWeekEndDate() {
var weekEndDate = new Date(nowYear, nowMonth, nowDay + (6 - nowDayOfWeek));
return formatDate(weekEndDate);
} // Get the start date of this month
function getMonthStartDate(){
var monthStartDate = new Date(nowYear, nowMonth, 1);
return formatDate(monthStartDate);
} // Get the end date of the month
function getMonthEndDate(){
var monthEndDate = new Date(nowYear, nowMonth, getMonthDays(nowMonth));
return formatDate(monthEndDate);
} // Get the start time of last month
function getLastMonthStartDate(){
var lastMonthStartDate = new Date(nowYear, lastMonth, 1);
return formatDate(lastMonthStartDate);
} // Get last month end time
function getLastMonthEndDate(){
var lastMonthEndDate = new Date(nowYear, lastMonth, getMonthDays(lastMonth));
return formatDate(lastMonthEndDate);
} // Get the start date of the quarter
function getQuarterStartDate(){ var quarterStartDate = new Date(nowYear, getQuarterStartMonth(), 1);
return formatDate(quarterStartDate);
} // Or the end date of this quarter
function getQuarterEndDate(){
var quarterEndMonth = getQuarterStartMonth() + 2;
var quarterStartDate = new Date(nowYear, quarterEndMonth, getMonthDays(quarterEndMonth));
return formatDate(quarterStartDate);
}

  

js More articles about time periods

  1. js The date is bigger ,js Judge whether the date is in the range ,js Judge whether the time period is in another time period

    /** * Date resolution , String to date * @param dateString It can be for 2017-02-16,2017/02/16,2017.02.16 * @returns {Date} Returns the corresponding date pair ...

  2. js Judge whether the current time is in a certain period of time

    js Judge the current time ( Or selected time ) Whether in a certain period of time We can use jutils - JavaScript Common function library isDuringDate Function to implement Pass in beginDateStr ( Starting time ) ...

  3. js Judge whether the machine is installed app

    demand : In the browser or app webview Page opened in ,js Judge whether the Sohu News client has been installed on this machine . One . WeChat 1. Share —— Good friends / Circle of friends ,feed There will be Sohu News signs , open url Suffix parameters isappinstalle ...

  4. js Determine whether the web page has been loaded Including pictures

    <script type="text/javascript" language="JavaScript"> //:  Determine whether the web page is loaded docum ...

  5. Make style files for different resolutions , Use... In the head of the page js After judging the resolution, dynamically load the defined style file

    Make style files for different resolutions , Use... In the head of the page js After judging the resolution, dynamically load the defined style file . The naming format of style file is as follows :forms[_ Screen width ].css, In the style file, you just need to redefine the width of the text box and the drop-down box . In the included header file ...

  6. JS Judge whether the web page is opened in wechat /

    JS Judge whether the web page is opened in wechat , The code is as follows : <script type="text/javascript"> function is_weixn(){ var ua = n ...

  7. js Determine whether the current page is on the mobile device or PC Open in the end

    Method 1 : var isPC = function () { var userAgentInfo = navigator.userAgent.toLowerCase(); var Agents = ne ...

  8. js Judge undefined type

    js Judge undefined type if (reValue== undefined){    alert("undefined");    }  I can't tell , Finally, I checked the information to use ty ...

  9. js You can only input numbers and you can only input

    JS The judgment can only be numbers and decimal points 1. Only numeric codes can be entered in the text box ( You can't enter a decimal point ) <input onkeyup="this.value=this.value.replace(/\D/g,'' ...

Random recommendation

  1. Struts2 Realization ajax Two ways

    be based on Struts2 Under the framework Ajax There are two ways , The first is the original sound , The other is struts2 With a plug-in . js Part of the call is the same : JS Code : function testAjax() { var ...

  2. java Container learning

    The container is java An important part of , The structure of the interface is as follows Collection | ------------------ Map | | | Set List HashMap | HashSet seeing the name of a thing one thinks of its function , Containers ...

  3. No apple browser Safari A way to recognize a number as a phone number

    By chance ipad When visiting my website , I found that a series of numbers on the website changed color ( It turned out to be red ), Now it's blue . At first I thought something was wrong with the website , Later on PC End view , The color is still red . stay ipad Click on the menu will also pop up call options ...

  4. XAlign: For code alignment Xcode plug-in unit

    Except for the plug-in alignment below ,xcode Bring with you cmd+v, Without copying or cutting , Directly by cmd+v It has the function of aligning the colon of the parameter label . XAlign  It's a Xcode Practical plug-ins for , Used to align specification code . Except for the plug-in author   ...

  5. SQL Server Maintenance plan to achieve database backup (Step by Step)

    from :http://www.cnblogs.com/gaizai/archive/2011/11/18/2254445.html One . Preface SQL Server  Backup and restore strategy , It includes passing through SSM ...

  6. Java note ( Ten )&hellip;&hellip; object-oriented II encapsulation (Encapsulation)

    Packaging concept encapsulation : Hidden object attributes and implementation details , Only public access is provided . benefits : Isolate change . Easy to use . Improve reusability . Improve safety . Encapsulation principle : Hide content that doesn't need to be provided externally . Hide all attributes , carry ...

  7. Codeforces Round #436 (Div. 2) E. Fire

    http://codeforces.com/contest/864/problem/E The question : There's a bunch of things , Each item has 3 Attributes , Time required , Expiration time ( In limine ) And value . You can only choose items one by one ( It's about choosing ...

  8. NHibernate Query sample collection

    The basic query   Examples of complex queries /// <summary> /// Get the part of the custom form data that belongs to the Department /// </summary> /// <param name=&quo ...

  9. prometheus Configuration is introduced

    prometheus Configuration is introduced prometheus Configuration points global.alerting.rule_files.scrape_configs 1.global( Global configuration ) scrape_interv ...

  10. 【 Answer key 】 bzoj1076: [SCOI2008] Reward level ( Loading and pressing + expect dp)

    Poke me in the face Solution I don't know how to do it , After reading the solution, I have a general understanding of . It's hard to expect this qwq We define \(dp[i][j]\) It means the first one \(i\) Step , The state before getting the treasure is \(j\). There will be a lot of illegal situations in the future , ...