js operation time

First, access to the current time display (time is the current time) of the form 2019-06-23 20:30:00 

var data_time = new Date();
var time = data_time.getFullYear() + "-" + ("" + (data_time.getMonth() + 101))
                    .substring(1) + "-" + ("" + (data_time.getDate() + 100)).substr(1) + " " + ("" + (data_time.getHours() + 100))
                    .substr(1) + ":" + ("" + (data_time.getMinutes() + 101)).substr(1) + ":" + ("" + (data_time.getSeconds() + 101)).substr(1);

  

Second, the conversion database in the form of datetime format 2019-06-23 20:30:00

function timeconvert (Time) { // the data type conversion background datetime: time acquired here have the form: 2018-05-19T08: 04: 52.000 + 0000 
                    var D = new new a Date (Time);
                     var Times = D. the getFullYear () + "-" + ( "" + (d.getMonth () + 101)) the substring (. 1) +. "-" + ( "" + (d.getDate () + 100 .)) substr (
                             . 1 ) +
                        " " + ("" + (d.getHours() + 100)).substr(1) + ":" + ("" + (d.getMinutes() + 101)).substr(1);
                    //    + ":" + ("" + (d.getSeconds() + 101)).substr(1);
                    return times;
                }

  

Three, it is determined whether the time is within seven days

  Such as: determining whether the time is the current time within seven days, may be determined whether the time difference between any two seven days

  May not necessarily seven days, following the corresponding change 604,800,000 milliseconds can be a day is 86,400,000 milliseconds, so 86400000 x 7 = 604800000

// conversion value in milliseconds 
the let DATE = new new a Date (2019, 06, 30) .getTime (); // arbitrary date
nowdate the let = new new a Date (data_time.getFullYear (), (data_time.getMonth () +. 1 ), data_time.getDate ()) the getTime ();. // This is obtained by the first method of the current time

// 604,800,000 seven days millisecond value 
IF (nowdate + 604 800 000> DATE) { // If the selected time within 7 days of the current date or prior to 
    the console.log ( "7 days or before" );
} The else { // If the selection time after 7 days of the current date 
    the console.log ( "After 7 days" );                                
}

 

Guess you like

Origin www.cnblogs.com/attentle/p/11074855.html