Calculate the time difference in milliseconds between UTC time and your local time and store the result in a variable. To calculate your local offset, call the getTimezoneOffset() method of your Date object and multiply its return value by 60,000 (e.g., “var localOffset = fooDay.getTimezoneOffset() * 60000”). You multiply by 60,000 to convert minutes into milliseconds (1,000 milliseconds in one second * 60 seconds in one minute = 60,000 milliseconds).
Obtain the UTC value in milliseconds of your Date object by calling its getTime() method and adding the return value to your local offset (e.g., “var fooUTC = fooDay.getTime() + localOffset”).
Create a constant to represent the Eastern Time Zone offset in milliseconds (e.g., “const EAST = 3600000 * -5”). You multiply by 3,600,000 to convert hours into milliseconds (1,000 milliseconds in one second * 60 seconds in one minute * 60 minutes in one hour = 3,600,000 milliseconds), and you multiply by -5 because Eastern Time is five hours behind UTC time.
Instantiate another Date object by calling the Date() constructor, passing to it as its sole parameter the sum of the UTC value of the first Date object and your Eastern Time Zone offset constant (e.g., “var barDay = new Date(fooUTC + EAST)”). This Date object represents your original UTC date, now converted to Eastern Time.
- Ciaran Griffin/Lifesize/Getty Images