无法在 Win CE 设备上设置时间 [英] Unable to set time on Win CE device

查看:25
本文介绍了无法在 Win CE 设备上设置时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个软件,其中时间非常重要.因此,每次传输一些数据时,我都会在 win ce 设备上设置时间.我通过套接字 DateTime.Now.Ticks 传输槽并使用

I created a software, where time is very important. Because of this every time some data is transferred I set also the time on the win ce device. I transfer trough socket DateTime.Now.Ticks and set time with

[DllImport("coredll.dll")] 私有外部静态 uintSetSystemTime(ref SYSTEMTIME lpSystemTime);

[DllImport("coredll.dll")] private extern static uint SetSystemTime(ref SYSTEMTIME lpSystemTime);

时区在 PC 上正确设置为 GMT+1,其中服务器应用程序正在运行并且也在设备上.设备上的 HomeDST 为 0.

Time zone is set correctly to GMT+1 on PC, where server application is running and also on device. HomeDST is 0 on device.

我的问题是,操作系统中的时间和我的软件中的时间之间总是存在一小时的差异.我使用

My problem is, that there is always one hour difference between time in OS and time in my software. I retrieving time using

[DllImport("coredll.dll")] private extern static voidGetSystemTime(ref SYSTEMTIME lpSystemTime);

[DllImport("coredll.dll")] private extern static void GetSystemTime(ref SYSTEMTIME lpSystemTime);

例如,在设备的右上角,我看到的是 9:12,而不是应用程序中的 8:12.

So for example on the right upper corner in device I see 9:12, than in application 8:12.

有人对此有解释/解决方案吗?这将是非常有帮助的,因为不幸的是,应用程序已经在实时系统中使用了,这会带来很大的问题......

Do have anybody an explanation / solution for this? It will be very helpfull, because application is unfortunatelly already used in live system and this one make a huge problems...

推荐答案

SetSystemTime 采用 UTC 时间(请参阅 http://msdn.microsoft.com/en-gb/library/windows/desktop/ms724942(v=vs.85).aspx)

SetSystemTime takes the time in UTC (see http://msdn.microsoft.com/en-gb/library/windows/desktop/ms724942(v=vs.85).aspx)

因此,如果您从服务器获取时间为 +1,则应在将其传递给 SetSystemTime() 之前对其调用 .ToUniversalTime().

So if you're getting time from your server which is +1, you should call .ToUniversalTime() on it before passing it to SetSystemTime().

作为一般规则,为了让您的生活更简单,我建议您在任何地方都将所有时间保持为 UTC,除非在 UI 中显示时 - 这是将它们转换为当地时间的时间.

As a general rule, to make your life simpler, I'd advise keeping all your times as UTC, everywhere, except when displaying in the UI - that's the time to translate them to local time.

这篇关于无法在 Win CE 设备上设置时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆