首页 新闻 会员 周边

WP8 如何通过C#代码设置系统时间

0
悬赏园豆:20 [待解决问题]

如题,询问一下如何使用C#获取国家网络授时中心的时间并设置系统时间,如果C#不行的话,C++或是其他语言是否可以设置WP8系统时间?

学海无涯1999的主页 学海无涯1999 | 初学一级 | 园豆:154
提问于:2013-04-17 19:27
< >
分享
所有回答(4)
1

在wp里目前没有这么高的权限吧...

sun8134 | 园豆:98 (初学一级) | 2013-05-06 12:20
0

目前wp的api里面没有系统设置的 set 权限,并且get的东西都很少。。。

FreeWingInSky | 园豆:206 (菜鸟二级) | 2013-05-24 13:57
0

API中没有提供该属性的赋值操作,所以暂时没法实现的!

然后、没所以 | 园豆:5 (初学一级) | 2013-08-01 17:03
0

获取国家网络授时中心的时间:

public class Class1
    {
        public DateTime GetStandardTime()
        {
            string[,] 时间服务器 = new string[14, 2];
            int[] 搜索顺序 = new int[] { 3, 2, 4, 8, 9, 6, 11, 5, 10, 0, 1, 7, 12 };
            时间服务器[0, 0] = "time-a.nist.gov";
            时间服务器[0, 1] = "129.6.15.28";
            时间服务器[1, 0] = "time-b.nist.gov";
            时间服务器[1, 1] = "129.6.15.29";
            时间服务器[2, 0] = "time-a.timefreq.bldrdoc.gov";
            时间服务器[2, 1] = "132.163.4.101";
            时间服务器[3, 0] = "time-b.timefreq.bldrdoc.gov";
            时间服务器[3, 1] = "132.163.4.102";
            时间服务器[4, 0] = "time-c.timefreq.bldrdoc.gov";
            时间服务器[4, 1] = "132.163.4.103";
            时间服务器[5, 0] = "utcnist.colorado.edu";
            时间服务器[5, 1] = "128.138.140.44";
            时间服务器[6, 0] = "time.nist.gov";
            时间服务器[6, 1] = "192.43.244.18";
            时间服务器[7, 0] = "time-nw.nist.gov";
            时间服务器[7, 1] = "131.107.1.10";
            时间服务器[8, 0] = "nist1.symmetricom.com";
            时间服务器[8, 1] = "69.25.96.13";
            时间服务器[9, 0] = "nist1-dc.glassey.com";
            时间服务器[9, 1] = "216.200.93.8";
            时间服务器[10, 0] = "nist1-ny.glassey.com";
            时间服务器[10, 1] = "208.184.49.9";
            时间服务器[11, 0] = "nist1-sj.glassey.com";
            时间服务器[11, 1] = "207.126.98.204";
            时间服务器[12, 0] = "nist1.aol-ca.truetime.com";
            时间服务器[12, 1] = "207.200.81.113";
            时间服务器[13, 0] = "nist1.aol-va.truetime.com";
            时间服务器[13, 1] = "64.236.96.53";
            int portNum = 13;
            string hostName;
            byte[] bytes = new byte[1024];
            int bytesRead = 0;
            SocketEx.TcpClient client2 = new SocketEx.TcpClient();
            for (int i = 0; i < 13; i++)
            {
                hostName = 时间服务器[搜索顺序[i], 1];
                try
                {
                    client2.Connect(hostName, portNum);
                    System.IO.Stream ns = client2.GetStream();
                    bytesRead = ns.Read(bytes, 0, bytes.Length);
                    client2.Dispose();
                    break;
                }
                catch (System.Exception)
                {
                }
            }
            char[] sp = new char[1];
            sp[0] = ' ';
            System.DateTime dt = new DateTime();
            string str1;
            str1 = System.Text.Encoding.UTF8.GetString(bytes, 0, bytesRead);

            string[] s;
            s = str1.Split(sp);
            dt = System.DateTime.Parse(s[1] + " " + s[2]);
            dt = dt.AddHours(8);
            return dt;
        }
    }

 

 

wp8目前没有开放设置时间的api,所以c#无法实现!c++能否实现就不知道了,

~冻结~ | 园豆:39 (初学一级) | 2013-09-10 18:33
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册