Reputation: 592
What are the API provided in the Compact Framework to read the time (NOT in UTC!!) on a windows mobile based device?
I was able to get the device time in UTC with this code:
DateTime dt = DateLib.Now;
SystemTime sysTime = new SystemTime();
Windows.SystemTime.GetSystemTime(out sysTime);
Windows.SystemTime.ConvertTimeStructure(ref sysTime, out dt);
Windows.SystemTime.SetSystemTime(dt);
But I want the time as per the device's time zone. Thanks
Upvotes: 1
Views: 1648
Reputation: 1301
You can use DateTime.UtcNow to get the UTC Time. Get the current utc offset TimeZone
GetUtcOffset in order to get a TimeSpan.
http://msdn.microsoft.com/en-us/library/system.timezone.getutcoffset.aspx
Then you can get LocalTime = DateTime.UtcNow + TimeZone.GetUtcOffset
Upvotes: 1
Reputation: 67168
Why aren't you simply using the built-in, supported DateTime.Now
property?
EDIT
The Compact Framework caches timezone information on load, so any call to change the time zone after an app has loaded will not be reflected in a call to DateTime.Now.
Right now I assume you're P/Invoking GetSystemTime
, instead you should be P/Invoking GetLocalTime
.
Upvotes: 1