js timestamp format date format

Timestamp into a date, online search, several more or less a little problem that he order a bit, write a method

 

console.log (formatDate (1565280000000)) 

Output:

 2019-08-09 00:00:00

 

= Date.prototype.format function (datetime) 
{ 
       var DATE = new new a Date (datetime); // time stamp is required * 10 1000, the timestamp is not required by the case 13 1000 
                var year = the Date.getFullYear (), 
                    month The = ( "0" + (date.getMonth () +. 1)). Slice (-2 ), 
                    sDate = ( "0" + date.getDate ()). Slice (-2 ), 
                    hour = ( "0" date.getHours + ()). Slice (-2 ), 
                    minute = ( "0" + date.getMinutes ()). Slice (-2 ), 
                    SECOND = ( "0" + date.getSeconds ()). Slice ( -2 );
                // 拼接
                var result = year + "-"+ month +"-"+ sdate +" "+ hour +":"+ minute +":" + second;
                // 返回
                return result;
}

 

 

the formatDate (datetime) {
                 var DATE = new new a Date (datetime); // time stamp is required * 10 1000, the timestamp is not required by the case 13 1000 
                var year = the Date.getFullYear (), 
                    month The = ( "0" + (date.getMonth () +. 1)). Slice (-2 ), 
                    sDate = ( "0" + date.getDate ()). Slice (-2 ), 
                    hour = ( "0" + date.getHours () ) .slice (-2 ), 
                    minute . = ( "0" + date.getMinutes ()) Slice (-2 ), 
                    SECOND = ( "0" + date.getSeconds ()) Slice (-2. );
                 // stitching 
                var result = year + "-"+ month +"-"+ sdate +" "+ hour +":"+ minute +":" + second;
                // 返回
                return result;
            }

Guess you like

Origin www.cnblogs.com/langhua/p/11314815.html