jws-frontend/src/utils/datetime.ts

23 lines
435 B
TypeScript
Raw Normal View History

2024-04-02 11:02:16 +07:00
import 'moment/dist/locale/th';
import moment from 'moment';
moment.locale('th');
export function setLocale(locale: string) {
moment.locale(locale);
}
export function dateFormat(
date?: string | Date | null,
fullmonth = false,
time = false,
) {
const m = moment(date);
if (!m.isValid()) return '';
const month = m.format(fullmonth ? 'MMMM' : 'MMM');
return m.format(`DD ${month} YYYY ${time ? ' HH:mm' : ''}`);
}