Unfortunately NodeJS has nodes not have a native the printf() method and util.format() does not support padding %d, i.e. %02d. So I created a simple method to format a timestamp, i.e. MM/DD/YY HH:MM:SS. This may not work for every locale or in every situation, but I find it handy for some quick and dirty date formatting in NodeJS.

datefmt.js:

function datefmt(d) {

  return util.format("%d/%d/%d %d:%d:%d",
                       d.getMonth()+1,
                       d.getDay(),
                       d.getFullYear(),
                       d.getHours(),
                       d.getSeconds(),
                       d.getSeconds())

    .replace(/([ :\/])([0-9])([:\ ])/g, "$10$2$3")
    .replace(/([:\/])([0-9])([:\/])/g, "$10$2$3")
    .replace(/([ :])([0-9]$)/g, "$10$2")
    .replace(/(^[0-9])(\/)/g, "0$1$2");

}

Test:

$ node -e "$(cat datefmt.js);console.log(datefmt(new Date()));"
 12/05/2016 11:26:26

Of course there are other ways, such as parsing the toString() or using the printf NPM. This was just fun to figure out.