{"id":444,"date":"2025-09-26T13:05:50","date_gmt":"2025-09-26T05:05:50","guid":{"rendered":"https:\/\/yin.nnneri.me\/?p=444"},"modified":"2025-09-26T13:11:11","modified_gmt":"2025-09-26T05:11:11","slug":"time-h-%e5%ba%93%e5%9c%a8%e8%a7%a3%e9%a2%98%e6%97%b6%e7%9a%84%e4%bd%bf%e7%94%a8","status":"publish","type":"post","link":"https:\/\/yin.nnneri.me\/?p=444","title":{"rendered":"time.h \u5e93\u5728\u89e3\u9898\u65f6\u7684\u4f7f\u7528"},"content":{"rendered":"<h2>time.h<\/h2>\n<p>\u4e00\u4e2ac\u6807\u51c6\u5e93\uff0c\u7528\u4e8e\u5904\u7406\u65e5\u671f\u548c\u65f6\u95f4<\/p>\n<p>\u5bf9\u4e8e\u67d0\u9898\u76ee\uff1a<\/p>\n<blockquote><p>\n  <strong>\u9898\u76ee\u63cf\u8ff0<\/strong><br \/>\n  \u79e6\u65f6\u660e\u6708\u7cfb\u5217\u52a8\u6f2b\u8bb2\u8ff0\u4e86\u79e6\u706d\u516d\u56fd\uff0c\u5efa\u7acb\u4e2d\u56fd\u9996\u4e2a\u5e1d\u56fd\u5f00\u59cb\uff0c\u5230\u54b8\u9633\u88ab\u695a\u519b\u653b\u9677\u7ed3\u675f\uff0c\u65f6\u95f4\u8de8\u5ea630\u5e74\uff0c\u8bb2\u8ff0\u2026\u2026\u597d\u4e86\uff0c\u8bdd\u4e0d\u591a\u8bf4\uff0c\u52a8\u6f2b\u6bcf\u8fc7\u4e00\u5468\u66f4\u65b0\u4e00\u96c6\uff0c\u79e6\u65f6\u660e\u6708\u7cfb\u5217\u4e00\u822c\u4e00\u90e8520\u96c6\uff0c\u73b0\u5728\uff0c\u79e6\u65f6\u660e\u6708\u7b2c\u4e94\u90e8\u541b\u4e34\u5929\u4e0b\u7ed3\u675f\u4e86\uff0c\u5b66\u59d0\u5750\u7b49\u7b2c\u516d\u90e8\u6ca7\u6d77\u6a2a\u6d41\u5f00\u64ad\uff0c\u4f46\u662f\u5b66\u59d0\u4e0d\u60f3\u518d\u6bcf\u5468\u770b\u4e00\u96c6\uff0c\u5e0c\u671b\u4e00\u6b21\u770b\u8fc7\u763e\uff0c\u6240\u4ee5\uff0c\u5e0c\u671b\u4f60\u4eec\u76f4\u63a5\u544a\u8bc9\u5b66\u59d0\u7b2c\u516d\u90e8\u4ec0\u4e48\u65f6\u95f4\u7ed3\u675f\u3002<br \/>\n  <strong>\u8f93\u5165<\/strong><br \/>\n  \u8f93\u5165\u6570\u636e\u6709\u591a\u7ec4\uff0c\u4ee5EOF\u4e3a\u7ed3\u675f\u6807\u5fd7\uff0c\u6bcf\u7ec4\u8f93\u5165\u4e00\u4e2a\u65e5\u671f\uff0c\u683c\u5f0f\u4e3a\uff1ayyyy-mm-dd\u8868\u793a\u7b2c\u516d\u90e8\u5f00\u59cb\u7684\u65f6\u95f4<br \/>\n  <strong>\u8f93\u51fa<\/strong><br \/>\n  \u8f93\u51fa\u7b2c\u516d\u90e8\u7ed3\u675f\u7684\u5177\u4f53\u65e5\u671f\uff0c\u683c\u5f0f\u5982\u4e0byyyy-mm-dd\uff1b\n<\/p><\/blockquote>\n<p>\u9898\u76ee\u8981\u6c42\u8f93\u5165\u5f53\u524d\u65f6\u95f4 \u5e76\u5c06\u5f53\u524d\u65f6\u95f4\u52a0\u4e0a 7 * 519 \u5929<br \/>\n\u53ef\u4ee5\u4f7f\u7528time.h\u5e93\u7b80\u4fbf\u8ba1\u7b97<\/p>\n<hr \/>\n<p>\u4ecb\u7ecd\u5176\u4e2d\u51e0\u4e2a\u7c7b\u578b\u548c\u51fd\u6570<\/p>\n<p><strong>\u7c7b\u578b<\/strong><\/p>\n<ul>\n<li><code>time_t<\/code> \u65f6\u95f4\u7801 \uff0832\u4f4d\u4ee51970-01-01 0:0:0 UTC\u4e3a0\uff0c64\u4f4d\u4ee51900-01-01 0:0:0 UTC \u4e3a0\uff09\uff0c\u5355\u4f4d\u4e3a\u79d2<\/li>\n<li><code>struct tm<\/code> \u5b58\u50a8\u65e5\u671f\u5206\u91cf\u7684\u7ed3\u6784\u4f53\uff0c\u6709\n<ul>\n<li><code>int tm_sec<\/code> \u79d2<\/li>\n<li><code>int tm_min<\/code> \u5206<\/li>\n<li><code>int tm_hour<\/code> \u65f6<\/li>\n<li><code>int tm_mday<\/code> \u67d0\u4e2a\u6708\u7684\u7b2c\u51e0\u5929<\/li>\n<li><code>int tm_mon<\/code> \u67d0\u5e74\u7684\u7b2c\u51e0\u6708 \u4e00\u6708\u8bb0\u4e3a0<\/li>\n<li><code>int tm_year<\/code> \u4ece\u67d0\u5e74\uff081900\u62161970\uff0c\u53d6\u51b3\u4e8e\u8bbe\u5907\uff09\u5f00\u59cb\u8bb0\u4e3a0 \u7684\u5e74\u4efd<\/li>\n<li><code>int tm_wday<\/code> \u5468\u65e5\u4e3a\u8d77\u59cb \u5468\u65e5\u4e3a0<\/li>\n<li><code>int tm_yday<\/code> \u67d0\u5e74\u7684\u7b2c\u51e0\u5929 \u7b2c\u4e00\u5929\u8bb0\u4e3a0<\/li>\n<li><code>int tm_isdst<\/code> \u662f\u5426\u542f\u52a8\u590f\u4ee4\u65f6 -1 \u81ea\u52a8 0 \u7981\u6b62 1 \u542f\u52a8<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><strong>\u51fd\u6570<\/strong><\/p>\n<ul>\n<li>\u83b7\u53d6\u65f6\u95f4\n<ul>\n<li><code>time()<\/code> \u8bbe\u5907\u65f6\u95f4<\/li>\n<li><code>clock()<\/code> \u7a0b\u5e8f\u8fd0\u884c\u65f6\u95f4<\/li>\n<\/ul>\n<\/li>\n<li>\u8f6c\u6362\u65f6\u95f4\n<ul>\n<li><code>localtime()<\/code> \u8f6c\u6362\u4e3a\u672c\u5730\u65f6\u95f4<\/li>\n<li><code>gmtime()<\/code> \u8f6c\u6362\u4e3aUTC\u65f6\u95f4<\/li>\n<li><code>mktime()<\/code> <code>struct tm<\/code>\u8f6c\u6362\u4e3a<code>time_t<\/code><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u683c\u5f0f\u5316\u548c\u6bd4\u8f83\u8fd9\u91cc\u6ca1\u8bf4<\/p>\n<p><strong>\u4e00\u4e9b\u91cd\u8981\u7684\u4e1c\u897f<\/strong><br \/>\n\u65e5\u671f\u5206\u91cf\u7ed3\u6784\u4f53\u5185\u6210\u5458\u9700\u8981\u5168\u90e8\u8d4b\u503c<br \/>\n<code>tm_mday<\/code> \u4ece 1 \u5f00\u59cb\uff0c \u800c<code>tm_mon<\/code> \u4ece 0 \u5f00\u59cb<br \/>\n<code>gmtime()<\/code> \u9ed8\u8ba4\u7684\u662fUTC+0 \uff0c\u8fd9\u4f1a\u5bfc\u81f4\u4e2d\u56fd\u7684\u65f6\u95f4+8\u5c0f\u65f6\uff08\u56e0\u4e3a\u4e2d\u56fd+8\u533a\uff09<br \/>\n<code>localtime()<\/code> \u9ed8\u8ba4\u548c\u7cfb\u7edf\u65f6\u533a\u4fdd\u6301\u4e00\u81f4<\/p>\n<p><strong>\u5bf9\u4e0a\u8ff0\u9898\u76ee\u7684\u4e00\u79cd\u89e3\u6cd5<\/strong><\/p>\n<pre><code class=\"language-c \">#include &lt;stdio.h&gt;\n#include &lt;math.h&gt;\n#include &lt;time.h&gt;\n\nint main()\n{\n    struct tm time;\n    struct tm *outputTime;\n    time_t timestamp;\n    int year = 0, month = 0, day = 0;\n    while (scanf(\"%d-%d-%d\", &amp;year, &amp;month, &amp;day) != EOF) {\n        time.tm_year = year - 1900;\n        time.tm_mon = month - 1;\n        time.tm_mday = day;\n        time.tm_hour = 0;\n        time.tm_min = 0;\n        time.tm_sec = 0;\n        time.tm_isdst = 0;\n        timestamp = mktime(&amp;time);\n        timestamp += 7 * 24 * 60 * 60 * 519 * 1;\n        outputTime = localtime(&amp;timestamp);\n        printf(\"%d-%02d-%02d\\n\", outputTime-&gt;tm_year + 1900, outputTime-&gt;tm_mon + 1, outputTime-&gt;tm_mday);\n    }\n    return 0;\n}\n\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>time.h \u4e00\u4e2ac\u6807\u51c6\u5e93\uff0c\u7528\u4e8e\u5904\u7406\u65e5\u671f\u548c\u65f6\u95f4 \u5bf9\u4e8e\u67d0\u9898\u76ee\uff1a \u9898\u76ee\u63cf\u8ff0 \u79e6\u65f6\u660e\u6708\u7cfb\u5217\u52a8\u6f2b\u8bb2\u8ff0\u4e86\u79e6\u706d\u516d\u56fd\uff0c\u5efa\u7acb\u4e2d\u56fd\u9996\u4e2a\u5e1d\u56fd\u5f00\u59cb\uff0c\u5230\u54b8 &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[18],"tags":[],"class_list":["post-444","post","type-post","status-publish","format-standard","hentry","category-18"],"_links":{"self":[{"href":"https:\/\/yin.nnneri.me\/index.php?rest_route=\/wp\/v2\/posts\/444","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yin.nnneri.me\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yin.nnneri.me\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yin.nnneri.me\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yin.nnneri.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=444"}],"version-history":[{"count":3,"href":"https:\/\/yin.nnneri.me\/index.php?rest_route=\/wp\/v2\/posts\/444\/revisions"}],"predecessor-version":[{"id":533,"href":"https:\/\/yin.nnneri.me\/index.php?rest_route=\/wp\/v2\/posts\/444\/revisions\/533"}],"wp:attachment":[{"href":"https:\/\/yin.nnneri.me\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=444"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yin.nnneri.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=444"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yin.nnneri.me\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=444"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}