开发者

Problem converting a GMT date to local time using C#?

开发者 https://www.devze.com 2022-12-20 22:03 出处:网络
We have a Windows Mobile application writt开发者_开发问答en in C# (compact framework). Regional setting is set to (English) New Zealand. Time zone is set to GMT+12 New Zealand.

We have a Windows Mobile application writt开发者_开发问答en in C# (compact framework). Regional setting is set to (English) New Zealand. Time zone is set to GMT+12 New Zealand.

We store our dates in GMT/UTC format. We have a date 2010-02-18 18:00:00 in UTC

This time in New Zealand is 7:00 am.

When we call on a datetime object

starttime = starttime.ToLocalTime();

we get 9:00 am.

What are we doing wrong?


Have you specified the "kind" on that datetime? Something like this:

DateTime parsedStartTime = DateTime.SpecifyKind(
    DateTime.Parse(starttime),
    DateTimeKind.Utc);

DateTime localStartTime = parsedStartTime.DateToLocalTime();

That might help as it might not know that the datetime you have now is in the type of Utc (it is probably unspecified).

If that doesn't help maybe some of your code showing how you are setting starttime would help.

0

精彩评论

暂无评论...
验证码 换一张
取 消