c# - 如何与服务器同步 Windows Mobile 时间?

标签 c# windows-mobile windows-mobile-6.5

我正在使用带有 C# 3.5 的 Windows Mobile 6.5 SDK。我需要使用服务器 (ASP.NET) 日期/时间更改移动日期/时间。我找不到任何东西。

更新:我正在处理时区问题。如果服务器和客户端在同一时区,那么我没有问题。但如果时区不同,我就会面临问题。

最佳答案

在移动设备上更改时间并不难 - openNETCF 帮助器使它变得更容易,否则您需要执行以下操作:

    // Compiling for Windows Mobile
    [DllImport("coredll.dll")]
    static extern bool SetLocalTime(ref SYSTEMTIME time);

    private void SetTime()
    {
        SYSTEMTIME st;

        // Thanks to Jim Hollenhorst <hollenho@attbi.com>
        DateTime trts = DateTime.Now.AddMilliseconds(LocalClockOffset);


        st.year = (short)trts.Year;
        st.month = (short)trts.Month;
        st.dayOfWeek = (short)trts.DayOfWeek;
        st.day = (short)trts.Day;
        st.hour = (short)trts.Hour;
        st.minute = (short)trts.Minute;
        st.second = (short)trts.Second;
        st.milliseconds = (short)trts.Millisecond;

        SetLocalTime(ref st);
    }

SYSTEMTIME 在哪里:

    private struct SYSTEMTIME
    {
        public short year;
        public short month;
        public short dayOfWeek;
        public short day;
        public short hour;
        public short minute;
        public short second;
        public short milliseconds;
    }

而 LocalClockOffset 是预先计算的所需时间与当前时间之间的差值。

您查询的另一部分现在是与服务器同步。如果您将服务器同步到 time-a.nist.gov,那么您也可以将您的手机同步到同一服务器。

Valer Bocan 对此有出色的代码,这就是上述代码的来源。链接:http://www.bocan.ro/sntpclient

我没有这样做,但可能让您的服务器也充当时间服务器,而不是将您的手机指向您的服务器并使用相同的协议(protocol)?

最后是时区 - 在我的 PDA 项目中,我一直将日期时间作为 GMT 传递,并与 GMT 有 +/- 偏移。

关于c# - 如何与服务器同步 Windows Mobile 时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12722247/

相关文章:

c# - MySQL中只取第一个满足第二个条件的

c++ - 在多行文本编辑控件中自动显示垂直滚动条

uwp - 调试时访问模拟器/设备的存储

.net - 在 Windows Mobile 6.5 中禁用菜单栏

c# - 在 DLL 中使用 default 关键字

c# - 不使用 EF4.1 和 Automapper 的并行

c# - expression.bind 和 expression.assign 之间有什么区别(或 : what is special about MemberBinding)

c# - 如何在 c# .net CF 3.5 中使用 XmlDocument 向 xml 添加属性

c# - PictureBox 的 Paint 事件导致闪烁 - 我还能在哪里做这个?