0

I am trying to convert current JavaScript time into different time zones based on few conditions.

Times zones to which I need to convert are "PT", "PST" etc.

So, in order to do that I need to convert the current date into "PT" or other time zones conditionally. Most of the answers on stack-overflow direct to use "getTimezoneOffset()". But I didn't get any luck.

var now = new Date();
var offset = new Date().getTimezoneOffset();

How can I get offset of "PST", "PT" or any other time zones?

var convertedTime = now.toTimeString().split(' ')[0];
Sweetie
  • 1,298
  • 6
  • 24
  • 48
  • java script. not java – Sweetie May 22 '17 at 14:53
  • Use [Moment.js](https://momentjs.com/) instead of custom conversions – MysterX May 22 '17 at 14:54
  • I can't use any other js except customization of java script only. – Sweetie May 22 '17 at 14:55
  • But that is using moment.js and I can't use that. – Sweetie May 22 '17 at 14:57
  • 1
    There are other answers to that question which do not use momentjs. For instance [this one](https://stackoverflow.com/a/10088053/5459839). I am sure you'll be able to find out the offset expressed in minutes you need to pass to that function. – trincot May 22 '17 at 15:00
  • yes. this is now giving me some different time. I assume its the local time to that city whose offset is passed to the function. But the toLocaleString is converting the actual time to AM or PM. for eg: nd = Mon May 22 2017 23:13:36 GMT+0530 (India Standard Time) If time to that city is "Mon May 22 2017 23:13:36". ToLocale would convert it to 5/22/2017 11:13:36 PM. But don't need in AM or PM. just need 23:13:36 so I am not using Tolocale here – Sweetie May 23 '17 at 05:22

0 Answers0