< HTML > < head > < Meta charset = "UTF-. 8" > </ head > < body > </ body > < Script > / * FormatTime: Processing Time String @params: Template @return: Good character returns to the process string * / String.prototype.formatTime = function FormatTime (Template) { typeof Template === ' undefined ' ? Template = ' {0} of {1} {2} date January {3}: {4}:{5}' : Null ; // the this: a pointer to the string to be processed // acquisition date figures the let matchAry = the this .match ( / \ + D / G); // render template and data Template = template.replace ( / \ {( \ + D) \} / G, (X, Y) => { the let Val = matchAry [Y] || ' 00 ' ; val.length < 2 ? Val = ' 0 ' + Val:null; return val; }); return template; } let time = '2019-7-8 12:2:2'; console.log(time.formatTime());//=>2019年07月08日 12:02:02 </script> </html>