sober
Version:
Sober is a library of UI components designed with reference to Material You.
9 lines (8 loc) • 367 B
JavaScript
export const dateFormat = (date, format = 'yyyy-MM-dd') => {
if (typeof date === 'string')
date = new Date(date);
const Y = date.getFullYear();
const m = date.getMonth() + 1;
const d = date.getDate();
return format.replace('yyyy', Y.toString()).replace('MM', m.toString().padStart(2, '0')).replace('dd', d.toString().padStart(2, '0'));
};