views:

380

answers:

1

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?

+3  A: 

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.

Tim C
I added DateTimeStyles.AssumeUniversal to our ParseExact method and works fine.
Pentium10
Glad it worked!
Tim C