amar
amar

Reputation: 493

How to get date object timezone text in french?

When I use new Date() I get o/p as Mon Nov 30 2020 16:41:46 GMT-0500 (Eastern Standard Time). Can I get Eastern Standard Time in french? I tried with the following, but didn't work. Is there any method to return french text?

  var d = new Date();
  console.log(d);
  console.log(d.toLocaleString("fr-FR"));

I need to detect the visitor timezone and display it as Eastern etc.. timezone. Since, my app is in french, is there a way to get the visitor timezone and translate it into french. I know I can do it by using translate service. I am just curious if there is a method that translates the timezone automatically to desired language. Everything is translated with toLocaleString, just the Eastern Standard Time. I can pass options as const options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };, is there a option for EST.

Upvotes: 0

Views: 2012

Answers (1)

user206904
user206904

Reputation: 550

This works for me

 var d= new Date(); 
 var options = { weekday: 'long', year: 'numeric', month:'long', day: 'numeric' };
  //options.timeZone = "UTC";
  options.timeZoneName = "long";
  console.log(d.toLocaleDateString("fr-FR", options));

This prints "lundi 30 novembre 2020 à heure normale d’Europe centrale"

Modify the options to suit your needs :)

Upvotes: 1

Related Questions