sbt-idp/cope2n-fe/src/utils/time.ts
2024-03-05 16:15:59 +07:00

9 lines
505 B
TypeScript

export function datetimeStrToDate(dateTimeStr: string, targetTimeZone: string): string {
if (!dateTimeStr) {
return "";
}
const options: Intl.DateTimeFormatOptions = { timeZone: targetTimeZone, year: 'numeric', month: '2-digit', day: '2-digit' };
const date = new Date(dateTimeStr);
const convertedDateTimeStr = date.toLocaleDateString('en-US', options).split('/').reverse();
return convertedDateTimeStr[0] + "-" + convertedDateTimeStr[2] + "-" + convertedDateTimeStr[1];
}