p/invoke GetSystemTime() 方法给出错误的输出
我在应用程序中使用了 p/invoke GetSystemTime() 方法来获取当前系统日期时间,但它给出了错误的值,任何解决方案都是如此。
I used p/invoke GetSystemTime() method in my application to get the current system date time but it is giving wrong values any solution for this..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
啊,时间还有CF和WinCE。多有趣啊!除了您收到的所有其他好答案之外,还有其他事情需要了解:
Ah, time and the CF and WinCE. What fun! Along with all the other fine answers you've received there are other things to know:
为什么不使用
DateTime.Now
?Why don't you use
DateTime.Now
?问题是什么?
您的 p/invoke 签名正确吗?
您的结构布局正确吗?
您如何处理“返回”的结构指针?
What is the problem?
Is your p/invoke signature correct?
Is you struct laid out correctly?
How are you dealing with the struct pointer being 'returned' ?
如果返回的时间相差一小时,则说明您遇到了夏令时错误(可以使用 修补程序)。
GetSystemTime
返回协调世界时 (UTC)。您可能只想查找本地时间,在这种情况下,您需要调用GetLocalTime
(或者仅使用DateTime.Now
或DateTime.UtcNow
>,并跳过 PInvoke 内容)。If the time returned is off by one hour, then you're running into a Daylight Savings Time bug (which can be fixed with a hotfix).
GetSystemTime
returns the Coordinated Universal Time (UTC). You may be looking for just the local time, in which case you want to callGetLocalTime
instead (or just useDateTime.Now
orDateTime.UtcNow
, and skip the PInvoke stuff).错误的价值观是什么意思?
由于您询问的是 Windows CE,可能是您的系统不保存 RTC 并且在启动时不同步,导致根本没有正确的时间。
这是特定于平台的。任务栏中的时间和日期是否正确(假设图像中有该时间和日期)?
What do you mean by wrong values?
Since you are asking about Windows CE, it might be that your system does not save the RTC and does not sync on boot resulting in not having the correct time at all.
This is platform specific. Is the time and date correct in the taskbar (assuming you have that in the image)?