UNPKG

cloudapp-cli

Version:

22 lines (21 loc) 606 B
exports.format = function (date = new Date(), format = "yyyyMMdd_HHmmss") { const o = { "M+": date.getMonth() + 1, "d+": date.getDate(), "H+": date.getHours(), "m+": date.getMinutes(), "s+": date.getSeconds(), }; if (/(y+)/.test(format)) format = format.replace( RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length) ); for (const k in o) if (new RegExp("(" + k + ")").test(format)) format = format.replace( RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length) ); return format; };