34 lines
855 B
TypeScript
34 lines
855 B
TypeScript
|
|
/**
|
||
|
|
* Format a date string into Thai locale format (Date only)
|
||
|
|
* Example: 10 ม.ค. 67
|
||
|
|
*/
|
||
|
|
export const formatDate = (date: string | Date | null | undefined): string => {
|
||
|
|
if (!date) return '-';
|
||
|
|
|
||
|
|
const d = typeof date === 'string' ? new Date(date) : date;
|
||
|
|
|
||
|
|
return d.toLocaleDateString('th-TH', {
|
||
|
|
day: 'numeric',
|
||
|
|
month: 'short',
|
||
|
|
year: '2-digit'
|
||
|
|
});
|
||
|
|
};
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Format a date string into Thai locale format (Date and Time)
|
||
|
|
* Example: 10 ม.ค. 67 14:30
|
||
|
|
*/
|
||
|
|
export const formatDateTime = (date: string | Date | null | undefined): string => {
|
||
|
|
if (!date) return '-';
|
||
|
|
|
||
|
|
const d = typeof date === 'string' ? new Date(date) : date;
|
||
|
|
|
||
|
|
return d.toLocaleDateString('th-TH', {
|
||
|
|
day: 'numeric',
|
||
|
|
month: 'short',
|
||
|
|
year: '2-digit',
|
||
|
|
hour: '2-digit',
|
||
|
|
minute: '2-digit'
|
||
|
|
});
|
||
|
|
};
|