0

I am using C# 1.11 driver for mongodb. I noticed that when i use date for objectId creation and when i use CreationTime property to get the datetime it is different.

Can anyone explain why is this happening?

using date 10/14/2016 12:00:00 AM

var date = DateTime.ParseExact("20161014000000","yyyyMMddHHmmss", CultureInfo.InvariantCulture);

creating ObjectId

ObjectId oid = new ObjectId(date, 0 , 0 , 0);
oid.CreationTime // returns 10/14/2016 7:00:00 AM
new_learner
  • 65
  • 2
  • 10

1 Answers1

2

Might be because mongo modifies it by default (mongo's docs) to UTC: "MongoDB stores times in UTC by default, and will convert any local time representations into this form. Applications that must operate or report on some unmodified local time value may store the time zone alongside the UTC timestamp, and compute the original local time in their application logic."

Efi Shtainer
  • 394
  • 3
  • 8