js query time supplement

First look at the date of the operation JS:

Copy the code
var myDate = new Date();
myDate.getYear (); // Get the current year (2) 
myDate.getFullYear (); // get the full year (4, 1970 - ????) 
myDate.getMonth (); // Get the current month ( 0-11,0 behalf January) 
myDate.getDate (); // get the current day (1-31) 
myDate.getDay (); // get the current week X (0-6,0 for Sunday) 
myDate.getTime ( ); // get the current time (number of milliseconds from the start 1970.1.1) 
myDate.getHours (); // get the current number (0-23) hours 
myDate.getMinutes (); // get the current number of minutes (0-59 ) 
myDate.getSeconds (); // get the current number of seconds (0-59) 
myDate.getMilliseconds (); // get the current milliseconds (0-999) 
myDate.toLocaleDateString (); // get the current date
var MyTime = myDate.toLocaleTimeString (); // get the current time 
myDate.toLocaleString (); // get the date and time
Copy the code

 

Method of formatting the date of acquisition

Copy the code
// extended Date will be converted to a specified format Date String 
// month (M), day (D), h (H), minutes (m), seconds (S), quarter (q) may be 1- 2 placeholder 
// years (y) may be 1-4 placeholder milliseconds (S) with only a placeholder (1-3 digits) 
// example: 
// ( a Date new new ()) the Format. ( "the mM-dd-YYYY HH: mm: ss.s") ==> 2006-07-02 08: 09: 04.423 
// (new new a Date ().) the Format ( "YYYY- H MD: m: sS ") ==> 2006-7-2. 8:. 9: 4.18 
Date.prototype.Format = function (FMT) {
     var O = {
         " m + ": the this .getMonth () +. 1, // month 
        "d +": the this .getDate (), // day 
        "H +": the this .getHours(), //小时 
        "m+": this.getMinutes(), //
        "s+": this.getSeconds(), //
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
        "S": this.getMilliseconds() //毫秒 
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}

transfer: 
var time1 = new Date().Format("yyyy-MM-dd");
var time2 = new Date().Format("yyyy-MM-dd HH:mm:ss");  
Copy the code

 

First look at the date of the operation JS:

Copy the code
var myDate = new Date();
myDate.getYear (); // Get the current year (2) 
myDate.getFullYear (); // get the full year (4, 1970 - ????) 
myDate.getMonth (); // Get the current month ( 0-11,0 behalf January) 
myDate.getDate (); // get the current day (1-31) 
myDate.getDay (); // get the current week X (0-6,0 for Sunday) 
myDate.getTime ( ); // get the current time (number of milliseconds from the start 1970.1.1) 
myDate.getHours (); // get the current number (0-23) hours 
myDate.getMinutes (); // get the current number of minutes (0-59 ) 
myDate.getSeconds (); // get the current number of seconds (0-59) 
myDate.getMilliseconds (); // get the current milliseconds (0-999) 
myDate.toLocaleDateString (); // get the current date
var MyTime = myDate.toLocaleTimeString (); // get the current time 
myDate.toLocaleString (); // get the date and time
Copy the code

 

Method of formatting the date of acquisition

Copy the code
// extended Date will be converted to a specified format Date String 
// month (M), day (D), h (H), minutes (m), seconds (S), quarter (q) may be 1- 2 placeholder 
// years (y) may be 1-4 placeholder milliseconds (S) with only a placeholder (1-3 digits) 
// example: 
// ( a Date new new ()) the Format. ( "the mM-dd-YYYY HH: mm: ss.s") ==> 2006-07-02 08: 09: 04.423 
// (new new a Date ().) the Format ( "YYYY- H MD: m: sS ") ==> 2006-7-2. 8:. 9: 4.18 
Date.prototype.Format = function (FMT) {
     var O = {
         " m + ": the this .getMonth () +. 1, // month 
        "d +": the this .getDate (), // day 
        "H +": the this .getHours(), //小时 
        "m+": this.getMinutes(), //
        "s+": this.getSeconds(), //
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
        "S": this.getMilliseconds() //毫秒 
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}

transfer: 
var time1 = new Date().Format("yyyy-MM-dd");
var time2 = new Date().Format("yyyy-MM-dd HH:mm:ss");  
Copy the code

 

Guess you like

Origin www.cnblogs.com/AbnerLc/p/11136086.html