Created
August 18, 2022 07:55
-
-
Save GuppuBoss/4566d152a6ab5baa80f82406629b1b22 to your computer and use it in GitHub Desktop.
Convert Date to EST Timezone
This file contains hidden or 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 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