Skip to content

Instantly share code, notes, and snippets.

@GuppuBoss
Created August 18, 2022 07:55
Show Gist options
  • Save GuppuBoss/4566d152a6ab5baa80f82406629b1b22 to your computer and use it in GitHub Desktop.
Save GuppuBoss/4566d152a6ab5baa80f82406629b1b22 to your computer and use it in GitHub Desktop.
Convert Date to EST Timezone
const getESTTime = () => {
const strArray=['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
const options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', timeZone: 'America/Toronto' };
const date = new Date();
date.setDate(date.getDate() + 7);
const estDate = new Date(date.toLocaleString('en-US', options));
const d = estDate.getDate();
const m = strArray[estDate.getMonth()];
const y = estDate.getFullYear();
return '' + m + ', ' + (d <= 9 ? '0' + d : d) + ' ' + y;
}
console.log(getESTTime());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment