0

I have the following where i am formatting the moment date and storing it into an object as follows

async date(){
 var today=Moment() **// today gets stored as Wed Mar 16 2022 12:05:07 GMT+0200 (Standard Time)'**
var date= today.format("dddd,D MMM YYYY"); /**/ date gets stored as Wednesday,16 Mar 2022**
var name= **how do i add what the name of the country is thats been returned after the GMT+0200 so it would be Standard Time**
}

is there a format option that i can assign the Country name to an object? so the variable name will store the country?

  • 2
    There's no country in a date o.O _"...so it would be Standard Time"_ - "Standard Time" is also no country. – Andreas Mar 16 '22 at 10:19
  • @Andreas no i just put that as an example it picks up for example (South African Standard Time) –  Mar 16 '22 at 10:24
  • Does this answer your question? [Display local timezone name with moment.js](https://stackoverflow.com/questions/41536372/display-local-timezone-name-with-moment-js) – 0stone0 Mar 16 '22 at 10:26
  • 1
    Then your example is a terrible example ;) Also that's still no country. That's a daylight saving time indicator. – Andreas Mar 16 '22 at 10:26
  • 1
    What's the actual problem you try to solve with this? That looks like a [XY Problem](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem) to me. – Andreas Mar 16 '22 at 10:27
  • lol okay so how do i get the daylight saving time –  Mar 16 '22 at 10:27
  • [To check for DST you can use the `isDST()` function.](https://stackoverflow.com/questions/21918095/moment-js-how-to-detect-daylight-savings-time-and-add-one-day) – 0stone0 Mar 16 '22 at 10:36

1 Answers1

1

You can try like this to get the country name,

const countryName = moment.tz.guess(true);

'guess' will return the browser zone.

To get particular zone other than browser zone,

const countryName = moment.tz.zone('America/New_York').countries(); // This will return an array from which we can pass the value to locale()
moment.locale(countryName);
RGA
  • 303
  • 3
  • 11