Search code examples
c#mongodbmongodb-.net-driverutc

MongoDB UTC DateTime Format To Local Time


I am using MongoDB c# driver to insert data into MongoDB. When I pass DateTime it's automatically storing it in UTC Format. But i want to store that in Local UK time. How to set the field in MongoDB to save in local time format and how to change date that already exists in the MongoDB collection.


Solution

  • MongoDB provides an attribute which automatically does the trick.

    [BsonDateTimeOptions(Kind = DateTimeKind.Local)]
    

    might be helpful for someone.