prantlf / date-fns-timezone

Parsing and formatting date strings using IANA time zones for date-fns.
MIT License
137 stars 18 forks source link

How to set a new Date() value with dynamic timezone #19

Open yukanagai opened 4 years ago

yukanagai commented 4 years ago

How can I create a new Date() value set to a specific timezone -- and get the timezone offset programatically? Right now I'm hard coding the timezone but these change throughout the year with daylight savings etc.

var dateInTimezone = new Date("2020-03-03 10:00:00 UTC+8:00");

Is there a way to set new Date( date + getTimezoneVal )?

Example scenario: Submitting a date (ie. 2020-03-03 @ 10am) via a form -- but set the timestamp to 2020-03-03 10am HKT while you're in NYC.