1

I want to convert the date from one timeZone into another TimeZone

For Eg: "Sun May 01 2019 00:00:00 GMT+0530 (India Standard Time)" is the current date object , i want to convert the date based on timeZone Offset. consider the offset is '+4.0', Then i want the desired output such as "Sun May 01 2019 00:00:00 +04:00", i have used moment utcOffset but it gives result such as "Sun May 19 2019 22:30:00 GMT+0530".

Lokeshkumar S
  • 256
  • 2
  • 6

2 Answers2

0

You should take a look at this answer. The top answer provides a good way how to do it in vanilla javascript.

If you would like to use a library to achieve that, I would suggest to look into date-fns. It doesn't have the mutability issues that moment does. If you opt for using it, you should use it together with date-fns-timezone

Harijs Deksnis
  • 1,366
  • 1
  • 13
  • 24
0

Try https://momentjs.com/docs/

If you want more control and internalization. But the Date object will be relative to browser that instantiates it. To represent time use the unix epoch, (new Date).getTime() / 1000;.

See https://en.wikipedia.org/wiki/Unix_time

Snewedon
  • 2,410
  • 2
  • 13
  • 27