Problem converting a GMT date to local time using C#?
We have a Windows Mobile application written 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.
链接地址: http://www.djcxy.com/p/29370.html