Linq to SQL DateTime values are local (Kind=Unspecified) - How do I make it UTC?

后端 未结 8 1871
萌比男神i
萌比男神i 2020-12-05 03:43

Isn\'t there a (simple) way to tell Linq To SQL classes that a particular DateTime property should be considered as UTC (i.e. having the Kind property of the DateTime type t

8条回答
  •  忘掉有多难
    2020-12-05 04:31

    I use this way to specify the DateTimeKind on the fly:

    DateTime myDateTime = new DateTime(((DateTime)myUtcValueFromDb).Ticks, DateTimeKind.Utc);
    

提交回复
热议问题