C# Asp.Net 获取标准北京时间
2021/4/30 12:26:48
本文主要是介绍C# Asp.Net 获取标准北京时间,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
#region 获取北京时间 /// <summary> /// 获取北京时间 /// </summary> /// <returns></returns> public DateTime GetBeiJinTime() { string[,] arrList = new string[14, 2]; arrList[0, 0] = "time-a.nist.gov"; arrList[0, 1] = "129.6.15.28"; arrList[1, 0] = "time-b.nist.gov"; arrList[1, 1] = "129.6.15.29"; arrList[2, 0] = "time-a.timefreq.bldrdoc.gov"; arrList[2, 1] = "132.163.4.101"; arrList[3, 0] = "time-b.timefreq.bldrdoc.gov"; arrList[3, 1] = "132.163.4.102"; arrList[4, 0] = "time-c.timefreq.bldrdoc.gov"; arrList[4, 1] = "132.163.4.103"; arrList[5, 0] = "utcnist.colorado.edu"; arrList[5, 1] = "128.138.140.44"; arrList[6, 0] = "time.nist.gov"; arrList[6, 1] = "192.43.244.18"; arrList[7, 0] = "time-nw.nist.gov"; arrList[7, 1] = "131.107.1.10"; arrList[8, 0] = "nist1.symmetricom.com"; arrList[8, 1] = "69.25.96.13"; arrList[9, 0] = "nist1-dc.glassey.com"; arrList[9, 1] = "216.200.93.8"; arrList[10, 0] = "nist1-ny.glassey.com"; arrList[10, 1] = "208.184.49.9"; arrList[11, 0] = "nist1-sj.glassey.com"; arrList[11, 1] = "207.126.98.204"; arrList[12, 0] = "nist1.aol-ca.truetime.com"; arrList[12, 1] = "207.200.81.113"; arrList[13, 0] = "nist1.aol-va.truetime.com"; arrList[13, 1] = "64.236.96.53"; int port = 13; byte[] array3 = new byte[1024]; int len = 0; int[] array2 = new int[] { 3, 2, 4, 8, 9, 6, 11, 5, 10, 0, 1, 7, 12 }; TcpClient tcpClient = new TcpClient(); for (int i = 0; i < 13; i++) { string hostname = arrList[array2[i], 0]; try { tcpClient.Connect(hostname, port); NetworkStream stream = tcpClient.GetStream(); len = stream.Read(array3, 0, array3.Length); tcpClient.Close(); break; } catch { } } DateTime result = default(DateTime); if (len != 0) { string data = Encoding.ASCII.GetString(array3, 0, len); string[] arr = data.Split(new char[] { ' ' }); result = DateTime.Parse(arr[1] + " " + arr[2]); } return result; } #endregion
这篇关于C# Asp.Net 获取标准北京时间的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2022-03-01沐雪多租宝商城源码从.NetCore3.1升级到.Net6的步骤
- 2024-11-18微软研究:RAG系统的四个层次提升理解与回答能力
- 2024-11-15C#中怎么从PEM格式的证书中提取公钥?-icode9专业技术文章分享
- 2024-11-14云架构设计——如何用diagrams.net绘制专业的AWS架构图?
- 2024-05-08首个适配Visual Studio平台的国产智能编程助手CodeGeeX正式上线!C#程序员必备效率神器!
- 2024-03-30C#设计模式之十六迭代器模式(Iterator Pattern)【行为型】
- 2024-03-29c# datetime tryparse
- 2024-02-21list find index c#
- 2024-01-24convert toint32 c#
- 2024-01-24Advanced .Net Debugging 1:你必须知道的调试工具