Last active
January 9, 2022 17:34
-
-
Save rickyalmeidadev/6c8e055434f64ace36efedbcc01821b3 to your computer and use it in GitHub Desktop.
Fix timezone offset
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 fn = (string: string /* yyyy-mm-dd */): Date => { | |
const [year, month, day] = string.split('-').map(Number); | |
const date = new Date(year, month - 1, day); | |
return date; | |
}; |
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 fn = (date: Date): Date => { | |
date.setMinutes(date.getMinutes() + date.getTimezoneOffset()); | |
return date; | |
}; |
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 fn = (date: Date): Date => { | |
const copy = new Date(date) | |
copy.setMinutes(copy.getMinutes() + copy.getTimezoneOffset()); | |
return copy; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment