Can I make node.js Date always be in UTC/GMT?


My app runs on Linux servers, where the time is (naturally) set to UTC/GMT. However the app is developed on Mac desktops where the time is typically set to a local timezone.

I could change every new Date() in my code to run:

var date = new Date().getTime();

And thus ensure dates on the server are always GMT, but that seems inelegant.

I understand previous versions of node used to always return UTC/GMT. Is there any way to bring this behavior back?

Edit: Removed adding timezone offset to getTime() per comments – since getTime() is already in UTC.


You can use TZ configuration parameter of node.js as follows.

For bash (and related)

export TZ=UTC

For Powershell

$env:TC = 'UTC'

Then for both:

nodejs server/index.js

Answered By – Er. Mohit Agrawal

Answer Checked By – Marie Seifert (AngularFixing Admin)

Leave a Reply

Your email address will not be published.