1

I have a strange thing occurring and I hope someone can point out what i am missing.

In MongoDB I have a field DT that is of Type Date

An example of what the date looks like in MongoDB is 2014-10-01 10:28:04.329-04:00

When I query MongoDB from Node.js using MongoClient, Node.js is returning this:

2014-10-01T14:28:04.329Z

As i understand it the driver is suppose to convert UTC to local time. In my case it should be Eastern Time (EDT). Why would Node be adding 4 hours instead?

I am loading the date into MongoDB from Java using the Java driver. The variable is set using

new Date();
FarscapePROJ
  • 285
  • 3
  • 16
  • Are you sure it's the same date? Milliseconds are different and i don't think that should happen between timezones. Also 2014-10-01 02:28:04.096-04:00 is 2014-10-01 06:28:04.096Z – soulcheck Oct 01 '14 at 21:30
  • Some how in my copy and paste, it cut of the time for what is shown in Mongo. I fixed that in the post. – FarscapePROJ Oct 01 '14 at 22:02

1 Answers1

4

Node isn't adding 4 hours. Both show exactly the same instant.

2014-10-01 10:28:04.329-04:00

is exactly the same as

2014-10-01T14:28:04.329Z

only one is in a EDT timezone which has -04:00 offset to UTC (so it's four hours earlier there), and the other is in UTC.

Probably you have your server configured in EDT and your client is set to UTC or the other way around.

Unless you need the exact same strings, I wouldn't worry about it.

Or, even better, set both the client and server machine to the same timezone, preferably UTC.

soulcheck
  • 36,297
  • 6
  • 91
  • 90