Set Device Time on .NET CF

泄露秘密 提交于 2019-12-13 17:41:39

问题


Looking for a code sample that takes a .NET CF DateTime object, and sets the device's date and time to that date (and/or time zone). The purpose of this is to get the current "real" time off of a server via web service and set the device's time correctly.

Anyone done this before?


回答1:


You can use Opennetcf's DateTimeHelper class.

Alternatively you can p/invoke SetLocalTime.




回答2:


Regarding kgiannakakis' answer: Definitely the way to go, but if you don't want to require the entire OpenNETCF runtime DLL just to set the time, download the source code to the 1.4 version of the library (there are newer ones, but the source is not freely available above v1.4) and just pull out the DateTimeHelper Class (you may need to pull some dependencies too). And then compile it directly into your code... It will save you from unnecessary external files.




回答3:


P/Invoking SetSystemTime() is a better choice for this, especially if the device is in a different time zone than the server. However, there seems to be a bug in Windows Mobile 5 where it fails to properly deal with Daylight Savings Time, so sometimes the time set on the device with SetSystemTime is off by an hour.



来源:https://stackoverflow.com/questions/738615/set-device-time-on-net-cf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!