Js gets the date before and after the specified date, which is more practical in actual application. The following describes the specific implementation process for you. If you need it, refer
The Code is as follows:
Function getmonths (dateday ){
/* Obtain the month of the current date */
Var curDate = new Date (dateday );
Return curDate. getMonth () + 1;
};
Function getYears (dateday ){
/* Obtain the year of the current date */
Var curDate = new Date (dateday );
Return curDate. getFullYear ();
};
Function getCountDays (dateday ){
/* Conversion time */
Var curDate = new Date (dateday );
/* Get the current month */
Var curMonth = curDate. getMonth ();
/* Generate the actual month: Because curMonth is 1 less than the actual month, you need to add 1 */
CurDate. setMonth (curMonth + 1 );
/* Set the date to 0 */
CurDate. setDate (0 );
/* Return the number of days in the current month */
Return curDate. getDate ();
};
/*
Get the start time of yesterday. The default value is 1 day. The default value is not to return a short time.
Day: Start Time
Amount: the number of days
IsShortTime: whether to display a short time
*/
Function getBeforeDay (day, amount, isShortTime ){
If (Date. parse (day )! = Date. parse (day )){
Return false;
}
Var days = new Date (day)-1000*60*60*24 );
If (amount ){
Var number = parseInt (amount );
If (number & number> 0 &&! IsNaN (number )){
Days = new Date (day)-1000*60*60*24 * number );
}
}
Return dateFormat (days, isShortTime );
}
/*
Get the start time of tomorrow. The default value is 1 day. The default value is not to return a short time.
Day: Start Time
Amount: the number of days
IsShortTime: whether to display a short time
*/
Function getAfterDay (day, amount, istertime ){
If (Date. parse (day )! = Date. parse (day )){
Return false;
}
Day = new Date (day );
Var v = day. valueOf ();
Var days = new Date (v + 86400000 ));
If (amount ){
Var number = parseInt (amount );
If (number & number> 0 &&! IsNaN (number )){
Days = new Date (v + 86400000 * number ));
}
}
Return dateFormat (days, isShortTime );
}
/*
Formatting time. By default, no short time is returned.
Day: Date
IsShortTime: whether to display a short time
*/
Function dateFormat (day, isShortTime ){
If (Date. parse (day )! = Date. parse (day )){
Return false;
}
Var days = new Date (day );
If (isShortTime & isShortTime = true ){
Var hours = days. getHours () <10? "0" + days. getHours (): days. getHours ();
Var minutes = days. getMinutes () <10? "0" + days. getMinutes (): days. getMinutes ();
Var seconds = days. getSeconds () <10? "0" + days. getSeconds (): days. getSeconds ();
Return days. getFullYear () + "-" + (days. getMonth () + 1) + "-" + days. getDate () + "" + hours + ":" + minutes + ":" + seconds;
} Else {
Return days. getFullYear () + "-" + (days. getMonth () + 1) + "-" + days. getDate ();
}
}