Standard Date object:
General use toLocaleDataString or toLocaleString without toString.
Clock case:
<html> <head> <meta charset="utf-8"> <style> #clockbox{ padding: 15px 0; line-height: 50px; color: aqua; } </style> </head> <body> <div id="clockbox"> </div> </body> < Script > the let clockbox = document.querySelector ( " #clockbox " ); // zero padding function addZero (Val) { Val = Number The (Val); return Val < 10 ? ' 0 ' + Val: Val; } // converted into the desired format function the queryData () { the let Time = new new a date (), // get the current date year = time.getFullYear (), month The =time.getMonth () + . 1 , // 0-11 Day = time.getDate (), Week = time.getDay (), // 0-6 hours = time.getHours (), minutes = time.getMinutes (), seconds The = time.getSeconds (); // string splicing the let weekary = [ ' date ' , ' a ' , ' two ' , ' three ' , ' four ' , ' five ' , ' six ' ]; the let Result = `$ {year} in $ {addZero (month)} month $ {addZero (day)} days`; Result + = `weeks when $ {weekary [week]} $ {addZero (hours)} $ {addZero (minutes)} divided $ {addZero (seconds)} seconds `; clockbox.innerHTML = Result; } // every second executed once setInterval ( the queryData, 1000 ); </ Script > </ HTML >