You are reading a single comment by @MaBe and its replies. Click here to read the full conversation.
  • How to write this correct?

    var replaceList  = { 
      yyyy: "d.getFullYear()", 
      yy:   "d.getFullYear().substr(-2)",
      mm:   "('0'+d.getMonth()).substr(-2)",
      dd:   "('0'+d.getDay()).substr(-2)",
      d:    "d.getDay()",
      m:    "d.getMonth()",
      HH:   "('0'+d.getHours()).substr(-2)",
      MM:   "('0'+d.getMinutes()).substr(-2)",
      SS:   "('0'+d.getSeconds()).substr(-2)",
      //.... and more 
    };
    
    // create time normal 
    var timePattern =  { 0: "HH:MM:SS ", 1: "HH:MM" };
    var timeN =  timePattern[0];
    replaceList.forEach(e => {
      timeN = timeN.replace(e,replaceList[e]);
    });
    console.log(timeN);
    
    
About

Avatar for MaBe @MaBe started