1

when I print the Date() it brings me the schedule of my machine, but I have a website that is accessed by different parts of the world and I need to show on the site the schedule of only a certain Country "BRAZIL" GMT 0300

Can someone help me ?

how to automatically convert the time showing in the application, regardless of where the user is accessing.

  • Use https://momentjs.com/ then you can do something like `moment.utc(utcTime).local().format()` – Get Off My Lawn May 19 '18 at 15:06
  • 1
    @GetOffMyLawn OP does not want `local`, he specifically wants brasilian time. – Bergi May 19 '18 at 15:10
  • 2
    @Bergi that doesn't change the fact that he could use that library wit the timezone piece. https://momentjs.com/timezone/ – Get Off My Lawn May 19 '18 at 15:12
  • Possible duplicate of [How to initialize javascript date to a particular timezone](https://stackoverflow.com/questions/15141762/how-to-initialize-javascript-date-to-a-particular-timezone) and/or [Convert date to another timezone in JavaScript](//stackoverflow.com/q/10087819) – Heretic Monkey May 19 '18 at 16:06

1 Answers1

2

Use toLocaleString() and specify a timezone like this:

console.log(
  new Date().toLocaleString("en-US", {timeZone: "America/Sao_Paulo"})
);
// 5/19/2018, 1:04:43 PM = Time in Brazil

Here is a list of timezones you can use.

peter bray
  • 1,325
  • 1
  • 12
  • 22