snappy-utils
Version:
A lightweight and efficient JavaScript utility library packed with commonly used helper functions like capitalize, debounce, deepClone, flattenArray, isPrime, and more. Ideal for developers who want a simple yet powerful toolkit to streamline everyday cod
14 lines (12 loc) • 456 B
JavaScript
function formatDate(date, format) {
const map = {
'MM': ('0' + (date.getMonth() + 1)).slice(-2),
'DD': ('0' + date.getDate()).slice(-2),
'YYYY': date.getFullYear(),
'HH': ('0' + date.getHours()).slice(-2),
'mm': ('0' + date.getMinutes()).slice(-2),
'ss': ('0' + date.getSeconds()).slice(-2),
};
return format.replace(/MM|DD|YYYY|HH|mm|ss/gi, matched => map[matched]);
}
module.exports = formatDate;