2024-11-11 13:03:40 -08:00
|
|
|
function basicLocalTimeFormat(time: string): string {
|
|
|
|
|
// Adjust the fractional seconds to milliseconds (3 digits)
|
|
|
|
|
time = time.replace(/\.(\d{3})\d*/, ".$1");
|
|
|
|
|
|
|
|
|
|
// Append 'Z' to indicate UTC time if not already present
|
|
|
|
|
if (!time.endsWith("Z")) {
|
|
|
|
|
time += "Z";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const date = new Date(time);
|
|
|
|
|
const localTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
|
|
|
|
|
|
|
|
// Format the date and time in the local time zone
|
|
|
|
|
const dateString = date.toLocaleDateString("en-US", {
|
|
|
|
|
weekday: "short",
|
|
|
|
|
year: "numeric",
|
|
|
|
|
month: "short",
|
|
|
|
|
day: "numeric",
|
|
|
|
|
timeZone: localTimezone,
|
|
|
|
|
});
|
|
|
|
|
const timeString = date.toLocaleTimeString("en-US", {
|
|
|
|
|
timeZone: localTimezone,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return `${dateString} at ${timeString}`;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-01 21:34:52 +03:00
|
|
|
function basicTimeFormat(time: string): string {
|
|
|
|
|
const date = new Date(time);
|
2024-06-25 12:18:44 -07:00
|
|
|
const dateString = date.toLocaleDateString("en-US", {
|
|
|
|
|
weekday: "short",
|
2024-04-01 21:34:52 +03:00
|
|
|
year: "numeric",
|
|
|
|
|
month: "short",
|
|
|
|
|
day: "numeric",
|
|
|
|
|
});
|
2024-06-25 12:18:44 -07:00
|
|
|
const timeString = date.toLocaleTimeString("en-US");
|
2024-11-11 13:03:40 -08:00
|
|
|
return `${dateString} at ${timeString} UTC`;
|
2024-04-01 21:34:52 +03:00
|
|
|
}
|
|
|
|
|
|
2024-10-14 13:07:54 -07:00
|
|
|
function timeFormatWithShortDate(time: string): string {
|
|
|
|
|
const date = new Date(time);
|
|
|
|
|
const dateString =
|
|
|
|
|
date.getMonth() + 1 + "/" + date.getDate() + "/" + date.getFullYear();
|
|
|
|
|
const timeString = date.toLocaleTimeString("en-US");
|
2024-11-18 06:04:16 -08:00
|
|
|
return `${dateString} at ${timeString} UTC`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function localTimeFormatWithShortDate(time: string): string {
|
|
|
|
|
// Adjust the fractional seconds to milliseconds (3 digits)
|
|
|
|
|
time = time.replace(/\.(\d{3})\d*/, ".$1");
|
|
|
|
|
|
|
|
|
|
// Append 'Z' to indicate UTC time if not already present
|
|
|
|
|
if (!time.endsWith("Z")) {
|
|
|
|
|
time += "Z";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const date = new Date(time);
|
|
|
|
|
const localTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
|
|
|
|
|
|
|
|
const dateString =
|
|
|
|
|
date.getMonth() + 1 + "/" + date.getDate() + "/" + date.getFullYear();
|
|
|
|
|
|
|
|
|
|
const timeString = date.toLocaleTimeString("en-US", {
|
|
|
|
|
timeZone: localTimezone,
|
|
|
|
|
});
|
|
|
|
|
|
2024-10-14 13:07:54 -07:00
|
|
|
return `${dateString} at ${timeString}`;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-18 06:04:16 -08:00
|
|
|
export {
|
|
|
|
|
basicLocalTimeFormat,
|
|
|
|
|
basicTimeFormat,
|
|
|
|
|
timeFormatWithShortDate,
|
|
|
|
|
localTimeFormatWithShortDate,
|
|
|
|
|
};
|