Reputation: 11354
In database I am storing the datetime in UTC,
I have class property like below,
public DateTime CollectionTimeUtc { get; set; }
Now when I am reading from database into C# object, it's automatically converted back to local time,
How to avoid this conversion ? I want it UTC. Thanks!
Upvotes: 0
Views: 108
Reputation: 151
Write your own explicit getter and setter, like the old way of writing properties in C#.
private DateTime collectionTimeUtc;
public DateTime CollectionTimeUtc
{
get { return collectionTimeUtc; }
set { collectionTimeUtc = value.ToUniversalTime(); }
}
Upvotes: 1