0

I cannot solve the seemingly simple problem of getting on my Node.js server (UTC) the timestamp of a certain point in time in a certain IANA timezone. Something like this:

getTsByTimezone('America/New_York', 2021, 2, 2, 17, 0, 0, 0) => int

I would not like to use third-party libraries Moment or the like.

Thank you!

Alex
  • 1,457
  • 1
  • 13
  • 26
  • [*This answer*](https://stackoverflow.com/a/61364310/257182) to [*Calculate Timezone offset only for one particular timezone*](https://stackoverflow.com/questions/61361914/calculate-timezone-offset-only-for-one-particular-timezone) might be what you're after. Given 2021-03-02T17:00:00, America/New_York it returns "2021-03-02 22:00:00" and offset -05:00. – RobG Dec 21 '20 at 22:46
  • @RobG thanks for your comment. I am currently using a similar approach. It doesn't look pretty. We need to create 5-6 `Date` objects for one moment in time, and my computer starts to slow down when processing an array of 200 such moments. I was hoping there was a way to make it easier. – Alex Dec 22 '20 at 08:01
  • You should only need to create 2 Dates: one for the initial offset estimate and one to check it's correct. More are needed only if the offset shifts the date over a daylight saving boundary, which should be rare, and only two additional dates are required at a maximum. The code at the linked answer runs in 3 to 5 ms locally, and that includes all the DOM stuff and additional processing of Dates for comparison. – RobG Dec 22 '20 at 08:19
  • @RobG in any case, this can be redone in response to the question I asked. If you do this I can mark it as correct. – Alex Jan 07 '21 at 07:57

0 Answers0