Skip to content

Instantly share code, notes, and snippets.

@rickyalmeidadev
Last active January 9, 2022 17:34
Show Gist options
  • Save rickyalmeidadev/6c8e055434f64ace36efedbcc01821b3 to your computer and use it in GitHub Desktop.
Save rickyalmeidadev/6c8e055434f64ace36efedbcc01821b3 to your computer and use it in GitHub Desktop.
Fix timezone offset
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;
};
const fn = (date: Date): Date => {
date.setMinutes(date.getMinutes() + date.getTimezoneOffset());
return date;
};
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