{"id":772,"date":"2009-12-03T12:24:00","date_gmt":"2009-12-03T04:24:00","guid":{"rendered":""},"modified":"2013-11-17T11:51:57","modified_gmt":"2013-11-17T03:51:57","slug":"%e8%bd%ac%e6%8d%a2%e6%97%b6%e9%97%b4%e4%b8%8e%e6%97%a5%e6%9c%9f%e5%88%b0gps%e6%97%b6","status":"publish","type":"post","link":"https:\/\/kyle.ai\/blog\/772.html","title":{"rendered":"\u8f6c\u6362\u65f6\u95f4\u4e0e\u65e5\u671f\u5230GPS\u65f6"},"content":{"rendered":"<p>\u624b\u4e0a\u4e00\u4e2a\u9879\u76ee\u8981\u7528\u5230\uff0c\u67e5\u4e86\u4e9b\u8d44\u6599\uff0c\u5199\u51fa\u4e86\u5176\u8ba1\u7b97\u7b97\u6cd5\u7684\u4ee3\u7801\uff0c\u8bb0\u5f55\u4e8e\u6b64\u3002<\/p>\n<p>C++\u7248\uff1a<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n#include &lt;stdio.h&gt;\r\n#include &lt;math.h&gt;\r\nint dinmth&#x5B;13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};\r\nint  GetGPSTime(int year,int month,int day,int hour,int minute,double second,double *gpstime)\r\n{\r\n  int   dayofw,dayofy, yr, ttlday, m, weekno;\r\n\/* \u68c0\u67e5\u65f6\u95f4\u662f\u5426\u8d85\u9650*\/\r\n  if (year &lt; 1981 || month &lt; 1 || month &gt; 12 || day &lt; 1 || day &gt; 31)\r\n     weekno = 0;\r\n\/*  \u8ba1\u7b97\u4e3a\u4eca\u5e74\u4e2d\u7684\u54ea\u4e00\u5929 *\/\r\n  if (month == 1)\r\n     dayofy = day;\r\n  else\r\n  {\r\n    dayofy = 0;\r\n    for (m=1; m&lt;=(month-1); m++)\r\n    {\r\n      dayofy += dinmth&#x5B;m];\r\n      if ( m==2 )\r\n      {\r\n if (year % 4 == 0 &amp;&amp; year % 100 != 0 || year % 400 == 0)\r\n    dayofy += 1;\r\n      }\r\n    }\r\n    dayofy += day;\r\n  }\r\n\/*  \u8ba1\u7b97GPS\u5468\u4e0eGPS\u79d2 *\/\r\n  ttlday = 360;\r\n  for (yr=1981; yr&lt;=(year-1); yr++)\r\n  {\r\n    ttlday  += 365;\r\n    if (yr % 4 == 0 &amp;&amp; yr % 100 != 0 || yr % 400 ==0)\r\n       ttlday  += 1;\r\n  }\r\n  ttlday += dayofy;\r\n  weekno  = ttlday\/7;\r\n  dayofw  = ttlday - 7 * weekno;\r\n  *gpstime =  (hour * 3600 + minute * 60 + second + dayofw * 86400);\r\n  if(weekno&gt;1024){weekno-=1024;}\r\n  return weekno;\r\n}\r\n\r\nvoid main()     \/\/\u4e3b\u51fd\u6570\r\n{   \r\n int weekno;\r\n\r\ndouble gpstime;\r\n\r\nweekno=GetGPSTime(2009, 12, 2, 19, 44, 30, &amp;gpstime);\r\n printf(&quot;%d %f&quot;,weekno,gpstime);\r\n scanf(&quot;%d&quot;,&amp;weekno);\r\n}\r\n<\/pre>\n<p>C#\u7248\uff1a <\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n     \/\/\/ &lt;summary&gt;\r\n        \/\/\/ \u5c06\u65e5\u671f\u548c\u65f6\u95f4\u8f6c\u6362\u4e3aGPS\u65f6\r\n         \/\/\/ &lt;\/summary&gt;\r\n        \/\/\/ &lt;param name=&quot;year&quot;&gt;&lt;\/param&gt;\r\n        \/\/\/ &lt;param name=&quot;month&quot;&gt;&lt;\/param&gt;\r\n        \/\/\/ &lt;param name=&quot;day&quot;&gt;&lt;\/param&gt;\r\n        \/\/\/ &lt;param name=&quot;hour&quot;&gt;&lt;\/param&gt;\r\n        \/\/\/ &lt;param name=&quot;minute&quot;&gt;&lt;\/param&gt;\r\n        \/\/\/ &lt;param name=&quot;second&quot;&gt;&lt;\/param&gt;\r\n        \/\/\/ &lt;param name=&quot;gpstime&quot;&gt;&lt;\/param&gt;\r\n        \/\/\/ &lt;param name=&quot;weekno&quot;&gt;&lt;\/param&gt;\r\n        public void GetGPSTime(int year, int month, int day, int hour, int minute, double second, ref double gpstime, ref int weekno)\r\n        {\r\n            int dayofw, dayofy, yr, ttlday, m;\r\n            if (year &lt; 1981 || month &lt; 1 || month &gt; 12 || day &lt; 1 || day &gt; 31)\r\n            {\r\n                weekno = 0;\r\n            }\r\n            if (month == 1)\r\n            {\r\n                dayofy = day;\r\n            }\r\n            else\r\n            {\r\n                dayofy = 0;\r\n                for (m = 1; m &lt;= (month - 1); m++)\r\n                {\r\n                    dayofy += dinmth&#x5B;m];\r\n                    if (m == 2)\r\n                    {\r\n                        if (year % 4 == 0 &amp;&amp; year % 100 != 0 || year % 400 == 0)\r\n                            dayofy += 1;\r\n                    }\r\n                }\r\n                dayofy += day;\r\n            }\r\n            ttlday = 360;\r\n            for (yr = 1981; yr &lt;= (year - 1); yr++)\r\n            {\r\n                ttlday += 365;\r\n                if (yr % 4 == 0 &amp;&amp; yr % 100 != 0 || yr % 400 == 0)\r\n                    ttlday += 1;\r\n            }\r\n            ttlday += dayofy;\r\n            weekno = ttlday \/ 7;\r\n            dayofw = ttlday - 7 * weekno;\r\n            gpstime = (hour * 3600 + minute * 60 + second + dayofw * 86400);\r\n            if (weekno &gt; 1024)\r\n            {\r\n                weekno -= 1024;\r\n            }\r\n        }\r\n<\/pre>\n<p>\u7528\u6cd5\uff1a<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\npublic partial class Form1 : Form\r\n    {\r\n        YUMA yuma = new YUMA();\r\n        public Form1()\r\n        {\r\n            InitializeComponent();\r\n        }\r\n\r\n        private void Form1_Load(object sender, EventArgs e)\r\n        {\r\n            DateTime currentTime = new DateTime();\r\n            currentTime = DateTime.Now;\r\n            int weekno=0;\r\n            double gpstime=0;\r\n            yuma.GetGPSTime(currentTime.Year, currentTime.Month, currentTime.Day, currentTime.Hour, currentTime.Minute, currentTime.Second, ref gpstime, ref weekno);\r\n            MessageBox.Show(weekno.ToString() + &quot;  &quot; + gpstime.ToString());\r\n        }\r\n    }\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u624b\u4e0a\u4e00\u4e2a\u9879\u76ee\u8981\u7528\u5230\uff0c\u67e5\u4e86\u4e9b\u8d44\u6599\uff0c\u5199\u51fa\u4e86\u5176\u8ba1\u7b97\u7b97\u6cd5\u7684\u4ee3\u7801\uff0c\u8bb0\u5f55\u4e8e\u6b64\u3002 C++\u7248\uff1a #include &lt;st [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-772","post","type-post","status-publish","format-standard","hentry","category-diary"],"_links":{"self":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/772","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/comments?post=772"}],"version-history":[{"count":2,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/772\/revisions"}],"predecessor-version":[{"id":4568,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/772\/revisions\/4568"}],"wp:attachment":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/media?parent=772"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/categories?post=772"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/tags?post=772"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}