UTC to local time using Linq to Entities

后端 未结 2 1700
無奈伤痛
無奈伤痛 2021-01-27 03:35

I need to translate a field from UTC to local time in a LINQ to Entities query. But it does not recognize the method \'System.DateTime ToLocalTime\' that I was intended to use.

2条回答
  •  遥遥无期
    2021-01-27 04:14

    What time zone would you expect that to use? The only one the database really knows about by default would probably be its own.

    Note that DateTime.Day only represents the day of the month - do you want June 10th and July 10th to count as the same day?

    If you can work out what time zone you're really interested in, that may suggest a potential solution - although I wouldn't like to guarantee it. It's possible that this is one of those cases where actually it makes sense to store the local date and time, as well as the time zone, rather than the UTC date/time. (This is appropriate if the local date/time is actually more important than the instant represented, compared to other values.)

提交回复
热议问题