0

I need to create a Javascript date object from a specific date in a specific timezone. For example "2023-03-26 02:00:00" in timezone "Europe/Helsinki". How can I do that?

I know that date is GTM+2, so I could do:

const date = new Date('2023-03-26T02:00:00.000+02:00');

But if I do it that way, I need to know the offset first. Issue is, that Helsinki is using daylight savings, so at "2023-03-26 02:00:00" the offset is +2h, but one hour later at "2023-03-26 03:00:00" the offset is +3h. Actually there is no time "03:00:00" at that date, because the time jumps to "04:00:00" after "02:59:59".

So, is there any way to provide date to javascript in a specific timezone without knowing the offset (and without using any date libraries)?

darx
  • 1,417
  • 1
  • 11
  • 25
  • 1
    "_So, is there any way to provide date to javascript in a specific timezone without knowing the offset (and without using any date libraries)?_": No – jsejcksn Mar 09 '23 at 08:29
  • you can use momentJs or DayJs or you can simply `new Date().toLocaleString('en', {timeZone: 'Asia/Dubai'})` – Sanu Khan Mar 09 '23 at 08:34

0 Answers0