- Skill level:
Other People Are Reading
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 local Offset = 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 get Time() method and adding the return value to your local offset (e.g., “var fooUTC = fooDay.getTime() + local Offset”).
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 bar Day = new Date(fooUTC + EAST)”). This Date object represents your original UTC date, now converted to Eastern Time.
Tips and warnings
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for