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);
@MaBe started
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
How to write this correct?