0

I am using moment-timezone

I have datetime with timezone string like below,

  • 02:10:02 EST 07/06/2018 (America/New_York)
  • 02:10:02 MST 07/06/2018 (America/Denver)
  • 02:10:02 CST 07/06/2018 (America/Chicago)
  • 02:10:02 PST 07/06/2018 (America/Los_Angles)

For above four strings I am able to convert to moment by doing just like

const momentTz = require('moment-timezone');
momentTz('02:10:02 EST 07/06/2018');
  • 02:10:02 IST 07/06/2018 (Asia/Calcutta)
  • 02:10:02 SGT 07/06/2018 (Asia/Singapore)

But When I am doing for singapore timezone string momentTz('02:10:02 SGT 07/06/2018'); It's giving me invalid date error.

Can you please help me with this, I need to convert this kind of datetime with timezone string to moment ?

I have datetime strings in different timezones.

Satyam Koyani
  • 4,236
  • 2
  • 22
  • 48
  • @NeilLunn I agree with you but I had an experience more then twice, my question was marked duplicate with reason as invalid tag. Anyways I should not presume. I am editing question. – Satyam Koyani Jun 08 '18 at 06:30
  • 2
    You should not indeed. Your core issue here is 3 letter abbreviations are not reliable. Multiple places share the same abbreviations and there are even actual variations in the offset from UTC within various abbreviated codes. This seems more of an issue with the "source" if have any control over that then it really needs to emit something standard like the offset in hours/minutes instead. MomentJS does not do it, and there's notes on issues that say they "will not do it". If you want to "guess" from these abbrevations then you need to look them up and convert yourself. – Neil Lunn Jun 08 '18 at 06:36

1 Answers1

0

Here is the link to all time zone allowed for moment.js. https://github.com/moment/moment-timezone/blob/develop/data/packed/latest.json

You can see "EST", "MST", "CST", "PST" are all listed but there is NO "SGT". You may use the same timeszone area like "Asia/Kuala_Lumpur" or "SMT" instead.

creswei
  • 54
  • 2