My app runs on Linux servers, where the time (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)
For Powershell
Then for both:
From the MDN docs on
Date#getTime
:Assuming you're storing dates/times as numbers (which I would recommend),
getTime
is already UTC, always.Suppose your client then requests a date from the server. If the server provides the date as
timestamp
, which is a number, the client can then do:And it will be correctly adjusted to the local time on the client.
Of course, maybe I'm misunderstanding your problem. But I just want to point out that this...
...should never really make sense. It's taking a UTC-based time and then offsetting it further, in essence double-offsetting a time.