2

I'm having a problem with NodeJS timezone. In my server.js file, i have the code below, but the time does not change to the correct timezone (-3h00)

process.env.TZ = 'America/Sao_Paulo';
console.log("Nova Data", new Date());

How can i fix this?

enter image description here

heavyrick
  • 384
  • 7
  • 16

1 Answers1

0

It looks like you need to set the env before you start the app.

When you change it by process.env zthe change can be seen only by new Date().toLocaleTimeString()

Check this answer or this

yeya
  • 1,968
  • 1
  • 21
  • 31
  • 1
    i'm using dotenv lib and configured .env file (TZ=America/Sao_Paulo) and does not work either. What surprises me it's when i print process.env.TZ, it shows the value i want, but timestamp remains incorrect. – heavyrick May 04 '18 at 17:59
  • 1
    the new date thing works (let date = new Date; let time = date.toLocaleTimeString();), but how can i change in the entire system ? – heavyrick May 04 '18 at 18:01