Files

20 lines
797 B
TypeScript

const padTwoDigits = (value: number): string => String(value).padStart(2, '0'); /* padTwoDigits 表示padTwoDigits。 */
/** Format a timestamp in the browser's current timezone. */
export const formatLocalDateTime = (value?: string | number | Date | null): string => {
if (value === undefined || value === null || value === '') return '-';
const date = value instanceof Date ? value : new Date(value); /* date 表示date。 */
if (Number.isNaN(date.getTime())) return '-';
return [
date.getFullYear(),
padTwoDigits(date.getMonth() + 1),
padTwoDigits(date.getDate()),
].join('-') + ' ' + [
padTwoDigits(date.getHours()),
padTwoDigits(date.getMinutes()),
padTwoDigits(date.getSeconds()),
].join(':');
}; /* formatLocalDateTime 表示formatLocalDateTime。 */