{"id":454,"date":"2025-06-10T20:40:41","date_gmt":"2025-06-10T12:40:41","guid":{"rendered":"https:\/\/www.zhaozhao123.cn\/php\/php-application-manual\/jcyy\/454.html"},"modified":"2025-06-10T20:40:41","modified_gmt":"2025-06-10T12:40:41","slug":"php%ef%bc%9a%e5%b0%86utc%e6%97%b6%e9%97%b4%e6%88%b3%e8%bd%ac%e6%8d%a2%e4%b8%ba%e6%9c%ac%e5%9c%b0%e6%97%b6%e9%97%b4%e6%88%b3%ef%bc%8c%e5%8f%8d%e4%b9%8b%e4%ba%a6%e7%84%b6","status":"publish","type":"my1js","link":"https:\/\/www.zhaozhao123.cn\/php\/my1js\/454.html","title":{"rendered":"PHP\uff1a\u5c06UTC\u65f6\u95f4\u6233\u8f6c\u6362\u4e3a\u672c\u5730\u65f6\u95f4\u6233\uff0c\u53cd\u4e4b\u4ea6\u7136"},"content":{"rendered":"<p><body><\/p>\n<h2>&#27010;&#35272;<\/h2>\n<p>&#22788;&#29702;PHP&#20013;&#30340;&#26102;&#21306;&#26159;&#19968;&#39033;&#24120;&#35265;&#30340;&#24320;&#21457;&#20219;&#21153;&#12290;&#26412;&#25945;&#31243;&#23558;&#25351;&#23548;&#24744;&#36890;&#36807;&#23558;UTC&#26102;&#38388;&#25139;&#36716;&#25442;&#20026;&#26412;&#22320;&#26102;&#38388;&#25139;&#20197;&#21450;&#21453;&#21521;&#25805;&#20316;&#65292;&#30830;&#20445;&#22312;&#24744;&#30340;&#24212;&#29992;&#20013;&#20934;&#30830;&#22788;&#29702;&#26102;&#38388;&#25968;&#25454;&#12290;<\/p>\n<h2>&#29702;&#35299;&#26102;&#21306;&#21644;UTC<\/h2>\n<p>&#21327;&#35843;&#19990;&#30028;&#26102;&#65288;UTC&#65289;&#20316;&#20026;&#20840;&#29699;&#26102;&#38388;&#26631;&#20934;&#65292;&#29992;&#20110;&#35843;&#33410;&#19990;&#30028;&#21508;&#22320;&#30340;&#38047;&#34920;&#21644;&#26102;&#38388;&#12290;&#23427;&#19981;&#23454;&#34892;&#22799;&#20196;&#26102;&#65292;&#19968;&#24180;365&#22825;&#20445;&#25345;&#19981;&#21464;&#12290;&#23558;UTC&#19982;&#26412;&#22320;&#26102;&#38388;&#36716;&#25442;&#28041;&#21450;&#19981;&#20165;&#20165;&#26159;&#31616;&#21333;&#30340;&#31639;&#26415;&#36816;&#31639;&#65292;&#36824;&#38656;&#35201;&#29702;&#35299;&#26102;&#21306;&#21644;&#22799;&#20196;&#26102;&#35268;&#21017;&#65292;&#36825;&#23436;&#20840;&#21487;&#20197;&#36890;&#36807;PHP&#20013;&#30340;DateTime&#21644;DateTimeZone&#31867;&#26469;&#22788;&#29702;&#12290;<\/p>\n<h3>&#22522;&#26412;&#30340;&#20174;UTC&#36716;&#25442;&#20026;&#26412;&#22320;&#26102;&#38388;&#30340;&#26041;&#27861;&#12290;<\/h3>\n<pre><code>\n$utcTimestamp = '2023-03-28 14:00:00';\n$timezone = new DateTimeZone('America\/New_York');\n$utcDateTime = new DateTime($utcTimestamp, new DateTimeZone('UTC'));\n$utcDateTime-&gt;setTimezone($timezone);\n\necho $utcDateTime-&gt;format('Y-m-d H:i:s');\n\/\/ Output: 2023-03-28 10:00:00\n<\/code><\/pre>\n<h3>&#23558;&#26412;&#22320;&#26102;&#38388;&#25139;&#36716;&#25442;&#20026;UTC&#12290;<\/h3>\n<pre><code>\n$localTimestamp = '2023-03-28 10:00:00';\n$timezone = new DateTimeZone('America\/New_York');\n$localDateTime = new DateTime($localTimestamp, $timezone);\n$localDateTime-&gt;setTimezone(new DateTimeZone('UTC'));\n\necho $localDateTime-&gt;format('Y-m-d H:i:s');\n\/\/ Output: 2023-03-28 14:00:00\n<\/code><\/pre>\n<h2>&#19982;Unix&#26102;&#38388;&#25139;&#24037;&#20316;<\/h2>\n<p>&#22312;Unix&#26102;&#38388;&#25139;&#34920;&#31034;&#33258;Unix&#32426;&#20803;&#65288;&#21363;1970&#24180;1&#26376;1&#26085;&#26684;&#26519;&#23612;&#27835;&#26631;&#20934;&#26102;&#38388;0&#28857;&#25972;&#65289;&#20197;&#26469;&#32463;&#36807;&#30340;&#31186;&#25968;&#65292;&#19988;&#19981;&#32771;&#34385;&#26102;&#21306;&#12290;PHP&#20063;&#21487;&#20197;&#36731;&#26494;&#22320;&#23558;Unix&#26102;&#38388;&#25139;&#36716;&#25442;&#20026;DateTime&#23545;&#35937;&#24182;&#26681;&#25454;&#38656;&#35201;&#20999;&#25442;&#26102;&#21306;&#12290;<\/p>\n<pre><code>\n$unixTimestamp = 1679995200; \/\/ corresponds to '2023-03-28 14:00:00' UTC\n$timezone = new DateTimeZone('America\/New_York');\n$dateTime = (new DateTime())-&gt;setTimestamp($unixTimestamp);\n$dateTime-&gt;setTimezone($timezone);\n\necho $dateTime-&gt;format('Y-m-d H:i:s');\n\/\/ Output: 2023-03-28 10:00:00\n<\/code><\/pre>\n<h2>&#28145;&#20837;DateTime&#65306;&#35843;&#25972;&#22799;&#20196;&#26102;&#26102;&#38388;<\/h2>\n<p>PHP&#30340;DateTime&#31867;&#20250;&#26681;&#25454;&#25552;&#20379;&#30340;&#26102;&#21306;&#33258;&#21160;&#35843;&#25972;Daylight Saving Time&#12290;&#22312;&#22788;&#29702;&#21487;&#33021;&#36866;&#29992;DST&#26085;&#26399;&#30340;&#26102;&#38388;&#25139;&#36716;&#25442;&#26102;&#65292;&#36825;&#19968;&#28857;&#33267;&#20851;&#37325;&#35201;&#12290;<\/p>\n<h3>&#39640;&#32423;&#31034;&#20363;&#65292;&#21253;&#25324;DST&#22788;&#29702;&#12290;<\/h3>\n<pre><code>\n$timestamp = '2023-11-05 01:30:00'; \/\/ DST change date in America\/New_York\n$nyTimezone = new DateTimeZone('America\/New_York');\n$utcDateTime = new DateTime($timestamp, $nyTimezone);\n$utcDateTime-&gt;setTimezone(new DateTimeZone('UTC'));\n\n\/\/ During DST change, New York shifts from UTC-04:00 to UTC-05:00\n\/\/ so 1:30 local time could be either before or after the change\n$firstPossibleUTC = clone $utcDateTime;\n$secondPossibleUTC = clone $utcDateTime;\n$secondPossibleUTC-&gt;modify('+1 hour');\n\necho 'First possible UTC: ' . $firstPossibleUTC-&gt;format('Y-m-d H:i:s') . \"n\";\necho 'Second possible UTC: ' . $secondPossibleUTC-&gt;format('Y-m-d H:i:s') . \"n\";\n\/\/ Potential Outputs:\n\/\/ First possible UTC: 2023-11-05 05:30:00\n\/\/ Second possible UTC: 2023-11-05 06:30:00\n<\/code><\/pre>\n<h2>&#22788;&#29702;&#21382;&#21490;&#26085;&#26399;&#21644;&#26102;&#21306;<\/h2>\n<p>PHP&#30340;DateTime&#31867;&#21487;&#20197;&#32771;&#34385;&#21382;&#21490;&#26102;&#21306;&#21464;&#21270;&#65292;&#36825;&#23545;&#20110;&#36828;&#22312;&#36807;&#21435;&#30340;&#26085;&#26399;&#25110;&#26410;&#26469;&#30340;&#26085;&#26399;&#38750;&#24120;&#37325;&#35201;&#12290;&#25552;&#20379;&#32773;&#22914;IANA&#23450;&#26399;&#26356;&#26032;&#26102;&#21306;&#25968;&#25454;&#65292;&#20197;&#20351;PHP&#33021;&#22815;&#36319;&#36394;&#36825;&#20123;&#21382;&#21490;&#35843;&#25972;&#12290;<\/p>\n<h3>&#39640;&#32423;&#22788;&#29702;&#21382;&#21490;&#26102;&#38388;&#25139;<\/h3>\n<pre><code>\n$historicTimestamp = '1918-03-31 02:00:00';\n$nyTimezone = new DateTimeZone('America\/New_York');\n$historicDateTime = new DateTime($historicTimestamp, $nyTimezone);\n$historicDateTime-&gt;setTimezone(new DateTimeZone('UTC'));\necho $historicDateTime-&gt;format('Y-m-d H:i:s');\n\/\/ Output: 1918-03-31 07:00:00\n<\/code><\/pre>\n<h2>&#20351;&#29992;&#30899;&#26469;&#22686;&#24378;&#26102;&#21306;&#22788;&#29702;<\/h2>\n<p>&#30899;&#26159;&#19968;&#20010;&#27969;&#34892;&#30340;PHP&#24211;&#65292;&#23427;&#25193;&#23637;&#20102;DateTime&#31867;&#65292;&#24182;&#31616;&#21270;&#20102;&#26085;&#26399;\/&#26102;&#38388;&#31649;&#29702;&#12290;&#23427;&#33258;&#21160;&#22788;&#29702;&#26102;&#21306;&#65292;&#24182;&#21487;&#20197;&#20351;&#26576;&#20123;&#20043;&#21069;&#30340;&#31034;&#20363;&#26356;&#31616;&#21333;&#12290;<\/p>\n<h3>&#20351;&#29992;&#30899;&#30340;&#20363;&#23376;<\/h3>\n<pre><code>\nuse CarbonCarbon;\nuse CarbonCarbonTimeZone;\n\n$carbonNow = Carbon::now(new CarbonTimeZone('UTC'));\necho 'UTC Now: ' . $carbonNow-&gt;toDateTimeString() . \"n\";\n\n$carbonNow-&gt;setTimezone('America\/New_York');\necho 'New York Now: ' . $carbonNow-&gt;toDateTimeString();\n\/\/ Outputs the current UTC time and then the equivalent time in New York.\n<\/code><\/pre>\n<h2>&#32467;&#35770;&#12290;<\/h2>\n<p>&#22312;&#26412;&#25945;&#31243;&#20013;&#65292;&#25105;&#20204;&#25506;&#35752;&#20102;&#22914;&#20309;&#20351;&#29992;PHP&#20013;&#30340;&#22810;&#20010;&#31034;&#20363;&#23558;UTC&#26102;&#38388;&#25139;&#36716;&#25442;&#20026;&#26412;&#22320;&#26102;&#38388;&#25139;&#12290;&#29702;&#35299;&#26102;&#21306;&#36716;&#25442;&#23545;&#20110;&#20219;&#20309;&#36328;&#36234;&#22810;&#20010;&#26102;&#21306;&#36816;&#34892;&#25110;&#21521;&#29992;&#25143;&#23637;&#31034;&#22320;&#29702;&#20301;&#32622;&#30456;&#20851;&#30340;&#26085;&#26399;&#21644;&#26102;&#38388;&#25968;&#25454;&#30340;&#24212;&#29992;&#31243;&#24207;&#33267;&#20851;&#37325;&#35201;&#12290;&#25105;&#20204;&#28085;&#30422;&#20102;&#20869;&#32622;&#30340;PHP&#20989;&#25968;&#65292;&#24182;&#35302;&#21450;&#20102;&#22914;Carbon&#31561;&#39069;&#22806;&#24037;&#20855;&#65292;&#36825;&#20123;&#24037;&#20855;&#21487;&#20197;&#36827;&#19968;&#27493;&#31616;&#21270;&#20320;&#22312;PHP&#20013;&#22788;&#29702;&#26085;&#26399;&#21644;&#26102;&#38388;&#32534;&#31243;&#30340;&#24037;&#20316;&#12290;<\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#27010;&#35272; &#22788;&#29702;PHP&#20013;&#30340;&#26102;&#21306;&#26159;&#19968;&#39033;&#24120;&#35265;&#30340;&#24320;&#21457;&#20219;&#21153;&#12290;&#038;#26..<\/p>\n","protected":false},"author":1,"featured_media":0,"menu_order":0,"template":"","meta":{"_acf_changed":false},"tags":[],"my1js2nav":[38],"tuisongtax":[],"class_list":["post-454","my1js","type-my1js","status-publish","hentry","my1js2nav-jcyy"],"acf":{"qian_art_seotitle":"","qian_art_seotitle_source":{"label":"SEO\u6807\u9898","type":"text","formatted_value":""},"qian_art_seokws":"","qian_art_seokws_source":{"label":"SEO\u5173\u952e\u8bcd","type":"text","formatted_value":""},"qian_art_stzhong":"","qian_art_stzhong_source":{"label":"\u4e2d | \u77ed\u6807\u9898","type":"text","formatted_value":""}},"_links":{"self":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js\/454","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js"}],"about":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/types\/my1js"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/users\/1"}],"wp:attachment":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/media?parent=454"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/tags?post=454"},{"taxonomy":"my1js2nav","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js2nav?post=454"},{"taxonomy":"tuisongtax","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/tuisongtax?post=454"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}