0

I have the following timezones:

enter image description here

when a user selects a timezone from the list how do i get whats the current time and date at that timezone? for example if i choose "Azores" i want to get the current date time for that area.

In moment i could use IANA timezones and pass the timezone like and format it to ("dddd, D MMM YYYY" )

moment().tz().guess;

but the user doesnt want to use IANA Timezones because they cant find some of the countries so i cant go with that option.

Is there a way i can determine the current datetime based on the timezones specified?

i also tried the following if i passed in the offset but that didnt work example:

moment().utcOffset("-01:00");

because its taking my local time and offsetting it so it doesnt give me the actual current datetime.

deanpillow
  • 121
  • 1
  • 10
  • The list in the picture is of Windows time zone ***display names*** - in English. They aren't identifiers at all, so you cannot use them for conversion. How are you generating the list? What is backing each value in the list? Show the code for how you create the list in your app. – Matt Johnson-Pint Jan 31 '23 at 04:37
  • Also, unless you're already locked-in to Moment for other reasons, you really should choose another library. See https://momentjs.com/docs/#/-project-status/ – Matt Johnson-Pint Jan 31 '23 at 04:38

1 Answers1

0

To get all available timezones:

How to get list of all timezones in javascript

const arr = Intl.supportedValuesOf('timeZone');

JS Date object is in UTC, so to get Date with timezone offset you can use

I want to get New York time in this JavaScript clock?

const date = new Date(new Date().toLocaleString("en-US", {timeZone: "America/New_York"}));
Jan Pfeifer
  • 2,854
  • 25
  • 35
  • Hi @jan i am not using IANA time zones , the user wants to use windows time zones as attached in the image .i need to pass for example (UTC+02:00 Cairo) – deanpillow Jan 30 '23 at 15:32
  • @deanpillow For that case check https://stackoverflow.com/questions/73482172/how-to-get-browser-timezone-in-javascript-then-convert-into-net-timezone-id – Jan Pfeifer Jan 31 '23 at 07:17