0

I have a date and need to convert it into this format 02/27/2020 3:00PM (MST)

What is the fastest way to do that in javscript like a one liner?

I tried

  var options = { weekday: 'short', year: 'numeric', month: 'short', day: 'numeric', hour: 'numeric', minute:'numeric', timeZoneName: 'short' };        
      this.date = new Date().toLocaleDateString("en-US", options);

This also does not work

new Date().toLocaleDateString(Intl.DateTimeFormat().resolvedOptions().timeZone, options);

as I am getting asia/caluctta invalid language tag

While this works for UnitedStates this does not work for users in russia, india, europe, china.

It will show the date as

02/28/2020 +500 GMT

I need it to show as

02/28/2020 (IST) for India

or

02/28/2020 (JST) for Japan Standard time

Terrance Jackson
  • 606
  • 3
  • 13
  • 40

1 Answers1

1

I can recommend you to try Moment.js. It's a javascript library made especially for easier manipulation with time. Just download the .js and add it to your index.html before your script.

jakubkoje
  • 11
  • 2
  • 1