Created
December 27, 2024 23:03
-
-
Save audinue/75086cd9a7a5429cc22a2b81d2544c26 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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