开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜