Skip to content

Instantly share code, notes, and snippets.

@audinue
Created December 27, 2024 23:03
Show Gist options
  • Save audinue/75086cd9a7a5429cc22a2b81d2544c26 to your computer and use it in GitHub Desktop.
Save audinue/75086cd9a7a5429cc22a2b81d2544c26 to your computer and use it in GitHub Desktop.
const changeTimeZone = (date: Date, timeZone: string) =>
new Date(
date.getTime() -
(date.getTime() -
new Date(date.toLocaleString("en-US", { timeZone })).getTime())
);
const dateTimeLocalValue = (date: Date) => {
const pad = (value: number) => value.toString().padStart(2, "0");
return (
date.getFullYear() +
"-" +
pad(date.getMonth() + 1) +
"-" +
pad(date.getDate()) +
"T" +
pad(date.getHours()) +
":" +
pad(date.getMinutes())
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment