9 lines
505 B
TypeScript
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];
|
|
} |