How to set the default time zone in Node.js?

Sometimes, we want to set the default time zone in Node.js.

In this article, we’ll look at how to set the default time zone in Node.js.

How to set the default time zone in Node.js?

To set the default time zone in Node.js, we can set the TZ environment variable.

For instance, we write

process.env.TZ = 'Europe/Amsterdam'

to set TZ to the 'Europe/Amsterdam' time zone.

Now all local times are returned in the Europe/Amsterdam time zone.

Conclusion

To set the default time zone in Node.js, we can set the TZ environment variable.