0

I have a Docker container with 'Debian GNU/Linux 8 (jessie)' and node.js 8. The system timezone (in /etc/timezone) is 'Europe/Moscow' but when I run node and type

new Date();

I get a UTC date, but not a local Moscow date.

How to make node.js use system timezone by default?

O. Jones
  • 103,626
  • 17
  • 118
  • 172
Dmitriano
  • 1,878
  • 13
  • 29

1 Answers1

1

Node.js is using your system's timezone, use the following to check:

new Date().toString()

When you do: new Date(), the output you get is in UTC, this differs from the output you get in Chrome's console, where new Date().toString() & new Date() gives the same string format. But that doesn't mean it's not using your system timezone. You're getting your current time, converted to UTC

console.log(new Date())

To confirm set a particular date:

console.log(new Date(2019,11,11,15,31,0).toString())
// Wed Dec 11 2019 15:31:00 {YOUR-TIMEZONE} 
Marcos Casagrande
  • 37,983
  • 8
  • 84
  • 98