{"id":456,"date":"2025-06-10T20:42:25","date_gmt":"2025-06-10T12:42:25","guid":{"rendered":"https:\/\/www.zhaozhao123.cn\/php\/php-application-manual\/jcyy\/456.html"},"modified":"2025-06-10T20:42:25","modified_gmt":"2025-06-10T12:42:25","slug":"php%ef%bc%9a%e5%b0%86%e6%97%b6%e9%97%b4%e6%88%b3%e8%bd%ac%e6%8d%a2%e4%b8%ba%e6%97%a5%e6%9c%9f%e6%97%b6%e9%97%b4%e5%8f%8a%e5%8f%8d%e4%b9%8b%e4%ba%a6%e7%84%b6","status":"publish","type":"my1js","link":"https:\/\/www.zhaozhao123.cn\/php\/my1js\/456.html","title":{"rendered":"PHP\uff1a\u5c06\u65f6\u95f4\u6233\u8f6c\u6362\u4e3a\u65e5\u671f\u65f6\u95f4\u53ca\u53cd\u4e4b\u4ea6\u7136"},"content":{"rendered":"<p><body><\/p>\n<h2>&#27010;&#36848;<\/h2>\n<p>&#22788;&#29702;&#26085;&#26399;&#21644;&#26102;&#38388;&#26159;&#32593;&#39029;&#24320;&#21457;&#20013;&#30340;&#24120;&#35265;&#20219;&#21153;&#12290;PHP &#25552;&#20379;&#20102;&#31616;&#21333;&#30340;&#26041;&#27861;&#26469;&#23558;&#26102;&#38388;&#25139;&#36716;&#25442;&#20026;&#20154;&#31867;&#21487;&#35835;&#30340;&#26085;&#26399;-&#26102;&#38388;&#26684;&#24335;&#65292;&#20197;&#21450;&#20174;&#36825;&#20123;&#26684;&#24335;&#24674;&#22797;&#21407;&#22987;&#26102;&#38388;&#25139;&#12290;&#29702;&#35299;&#36825;&#20123;&#36716;&#25442;&#21487;&#20197;&#22686;&#24378;&#23545;&#26085;&#26399;-&#26102;&#38388;&#25968;&#25454;&#30340;&#25805;&#20316;&#33021;&#21147;&#12290;<\/p>\n<h2>&#26102;&#38388;&#25139;&#30340;&#20171;&#32461;<\/h2>\n<p>&#22312;PHP&#20013;&#65292;&#26102;&#38388;&#25139;&#26159;&#25351;&#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;&#30340;&#31186;&#25968;&#65292;&#24182;&#29992;&#20110;&#23384;&#20648;&#25110;&#20256;&#36755;&#26085;&#26399;-&#26102;&#38388;&#25968;&#25454;&#20197;&#32039;&#20945;&#30340;&#24418;&#24335;&#36827;&#34892;&#23384;&#20648;&#25110;&#20256;&#36882;&#12290;PHP&#25552;&#20379;&#20102;&#20869;&#32622;&#20989;&#25968;&#26469;&#23558;&#26102;&#38388;&#25139;&#36716;&#25442;&#20026;&#26085;&#26399;-&#26102;&#38388;&#23383;&#31526;&#20018;&#21644;&#21453;&#20043;&#20134;&#28982;&#65292;&#25105;&#20204;&#23558;&#22312;&#27492;&#25351;&#21335;&#20013;&#25506;&#35752;&#36825;&#20123;&#21151;&#33021;&#12290;<\/p>\n<h3>&#23558;&#26102;&#38388;&#25139;&#36716;&#25442;&#20026;&#21487;&#35835;&#30340;&#26085;&#26399;&#26102;&#38388;<\/h3>\n<pre><code>&lt;?php\n$dateString = date('Y-m-d H:i:s', 1609459200); \/\/ output: 2021-01-01 00:00:00\n?&gt;<\/code><\/pre>\n<h3>&#23558;&#26085;&#26399;&#26102;&#38388;&#23383;&#31526;&#20018;&#36716;&#25442;&#20026;&#26102;&#38388;&#25139;&#12290;<\/h3>\n<pre><code>&lt;?php\n$timestamp = strtotime('2021-01-01 00:00:00'); \/\/ output: 1609459200\n?&gt;<\/code><\/pre>\n<h2>&#39640;&#32423;&#26085;&#26399;&#26102;&#38388;&#25805;&#20316;<\/h2>\n<p>PHP&#30340;DateTime&#31867;&#25552;&#20379;&#20102;&#19968;&#20010;&#38754;&#21521;&#23545;&#35937;&#30340;&#26041;&#27861;&#26469;&#22788;&#29702;&#26085;&#26399;&#21644;&#26102;&#38388;&#25805;&#20316;&#12290;&#23427;&#25903;&#25345;&#26356;&#22797;&#26434;&#30340;&#25805;&#20316;&#65292;&#22914;&#26102;&#21306;&#36716;&#25442;&#21644;&#26085;&#26399;&#36816;&#31639;&#12290;<\/p>\n<h3>&#26085;&#26399;&#26102;&#38388;&#31867;&#21644;&#26102;&#38388;&#25139;&#36716;&#25442;<\/h3>\n<pre><code>&lt;?php\n$dateTime = new DateTime('@1609459200');\n$dateTime-&gt;setTimezone(new DateTimeZone('America\/New_York'));\necho $dateTime-&gt;format('Y-m-d H:i:s'); \/\/ Adjusted for time zone\n?&gt;<\/code><\/pre>\n<h3>&#23545;&#20110;&#38750;&#20462;&#25913;&#25805;&#20316;&#65292;&#20351;&#29992;DateTimeImmutable&#12290;<\/h3>\n<pre><code>&lt;?php\n$dateTimeImmutable = new DateTimeImmutable('@1609459200');\n$dateTimeImmutable = $dateTimeImmutable-&gt;modify('+1 day');\n?&gt;<\/code><\/pre>\n<h3>&#20351;&#29992;IntlDateFormatter&#36827;&#34892;&#26412;&#22320;&#21270;<\/h3>\n<pre><code>&lt;?php\n$formatter = new IntlDateFormatter('en_US', IntlDateFormatter::FULL, IntlDateFormatter::FULL);\n$formatter-&gt;setPattern('yyyy-MM-dd HH:mm:ss');\n$formattedDate = $formatter-&gt;format(1609459200);\n?&gt;<\/code><\/pre>\n<h2>&#22788;&#29702;&#26102;&#38388;&#25139;&#19982;&#26102;&#21306;<\/h2>\n<p>&#26102;&#21306;&#20250;&#22797;&#26434;&#21270;&#26102;&#38388;&#25139;&#30340;&#36716;&#25442;&#38382;&#39064;&#12290;PHP&#30340;DateTimeZone&#31867;&#21644;DateTime&#21487;&#20197;&#26126;&#30830;&#22320;&#22788;&#29702;&#26102;&#21306;&#36716;&#25442;&#30340;&#38382;&#39064;&#12290;<\/p>\n<h3>&#26102;&#21306;&#36716;&#25442;&#31034;&#20363;<\/h3>\n<pre><code>&lt;?php\n$dateTime = new DateTime('now', new DateTimeZone('Europe\/London'));\n$timestampWithTimezone = $dateTime-&gt;getTimestamp();\n?&gt;<\/code><\/pre>\n<h2>&#26085;&#26399;&#26102;&#38388;&#36716;&#25442;&#20013;&#30340;&#38169;&#35823;&#22788;&#29702;<\/h2>\n<p>&#22312;&#26085;&#26399;&#26102;&#38388;&#19982;&#26102;&#38388;&#25139;&#20043;&#38388;&#30340;&#36716;&#25442;&#36807;&#31243;&#20013;&#65292;&#24517;&#39035;&#32771;&#34385;&#21040;&#21487;&#33021;&#23384;&#22312;&#30340;&#38169;&#35823;&#65292;&#20363;&#22914;&#26080;&#25928;&#30340;&#26684;&#24335;&#25110;&#31995;&#32479;&#30456;&#20851;&#38382;&#39064;&#65292;&#22914;&#24180;&#20221;2038&#38382;&#39064;&#12290;<\/p>\n<h3>&#39564;&#35777;&#26085;&#26399;&#26102;&#38388;&#26684;&#24335;<\/h3>\n<pre><code>&lt;?php\n$date = '2021-02-29';\nif (DateTime::createFromFormat('Y-m-d', $date) !== false) {\n    \/\/ It's a valid date\n} else {\n    \/\/ Handle invalid date\n}\n?&gt;<\/code><\/pre>\n<h3>&#24180;&#20221;&#38382;&#39064; Year 2038 Problem<\/h3>\n<p>&#22312;32&#20301;&#31995;&#32479;&#20013;&#65292;&#30001;&#20110;&ldquo;&#20108;&#21313;&#19968;&#19990;&#32426;&#38382;&#39064;&rdquo;&#65288;Year 2038&#38382;&#39064;&#65289;&#65292;&#26102;&#38388;&#25139;&#20250;&#28378;&#21160;&#36807;&#26399;&#12290;PHP&#30340;64&#20301;&#29256;&#26412;&#21644;DateTime&#31867;&#25552;&#20379;&#20102;&#35299;&#20915;&#26041;&#26696;&#12290;<\/p>\n<h2>&#26102;&#38388;&#38388;&#38548;&#21644;&#21608;&#26399;&#22788;&#29702;<\/h2>\n<p>&#26085;&#26399;&#38388;&#38548;&#21644;&#26085;&#26399;&#21608;&#26399;&#31867;&#25552;&#20379;&#20102;&#22788;&#29702;&#26102;&#38388;&#26377;&#25928;&#26399;&#20869;&#30340;&#26102;&#27573;&#21644;&#38388;&#38548;&#30340;&#26377;&#25928;&#21151;&#33021;&#12290;<\/p>\n<h3>&#28155;&#21152;&#21644;&#20943;&#21435;&#26102;&#38388;&#38388;&#38548;<\/h3>\n<pre><code>&lt;?php\n$dateTime = new DateTime();\n$dateTime-&gt;add(new DateInterval('P1D')); \/\/ Adds 1 day\n$dateTime-&gt;sub(new DateInterval('PT1H')); \/\/ Subtracts 1 hour\n?&gt;<\/code><\/pre>\n<h3>&#20351;&#29992;DatePeriod&#36827;&#34892;&#37325;&#22797;&#20107;&#20214;&#31649;&#29702;<\/h3>\n<pre><code>&lt;?php\n$startDate = new DateTime('today');\n$interval = new DateInterval('P1W');  \/\/ 1 week\n$endDate = new DateTime('next month');\n$period = new DatePeriod($startDate, $interval, $endDate);\nforeach ($period as $date) {\n    echo $date-&gt;format('Y-m-d H:i:s') . \"n\";\n}\n?&gt;<\/code><\/pre>\n<h2>&#24494;&#31186;&#21644;&#39640;&#20998;&#36776;&#29575;&#26102;&#38388;&#25139;<\/h2>\n<p>PHP&#30340;microtime&#20989;&#25968;&#20197;&#24494;&#31186;&#31934;&#24230;&#25429;&#33719;&#26102;&#38388;&#25139;&#65292;&#36825;&#23545;&#20110;&#24615;&#33021;&#20998;&#26512;&#21644;&#20195;&#30721;&#27979;&#37327;&#38750;&#24120;&#26377;&#29992;&#12290;<\/p>\n<h3>&#19982;MicroTime&#21512;&#20316;<\/h3>\n<pre><code>&lt;?php\n$timeStart = microtime(true);\n\/\/ Some time-consuming operation\n$timeEnd = microtime(true);\n$executionTime = $timeEnd - $timeStart;\necho \"Script took $executionTime seconds.\";\n?&gt;<\/code><\/pre>\n<h2>&#32467;&#35770;&#12290;<\/h2>\n<p>&#23558;&#26102;&#38388;&#25139;&#36716;&#25442;&#20026;&#21487;&#35835;&#26085;&#26399;&#21644;&#21453;&#20043;&#20134;&#28982;&#23545;&#20110;PHP&#24320;&#21457;&#20154;&#21592;&#26469;&#35828;&#26159;&#19968;&#39033;&#24517;&#35201;&#30340;&#25216;&#33021;&#12290;&#36890;&#36807;&#20351;&#29992;PHP&#30340;&#26085;&#26399;&#26102;&#38388;&#20989;&#25968;&#21644;&#23545;&#35937;&#21270;&#26085;&#26399;&#26102;&#38388;&#31867;&#65292;&#24320;&#21457;&#20154;&#21592;&#21487;&#20197;&#39640;&#25928;&#12289;&#20934;&#30830;&#22320;&#22788;&#29702;&#21508;&#31181;&#19982;&#26085;&#26399;&#26102;&#38388;&#30456;&#20851;&#30340;&#24037;&#20316;&#12290;<\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#27010;&#36848; &#22788;&#29702;&#26085;&#26399;&#21644;&#26102;&#38388;&#26159;&#32593;&#39029;&#24320;&#21457;&#20013;&#30340;&#24120;&#35265;&#20219;&#038;#21153..<\/p>\n","protected":false},"author":1,"featured_media":0,"menu_order":0,"template":"","meta":{"_acf_changed":false},"tags":[],"my1js2nav":[38],"tuisongtax":[],"class_list":["post-456","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\/456","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=456"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/tags?post=456"},{"taxonomy":"my1js2nav","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js2nav?post=456"},{"taxonomy":"tuisongtax","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/tuisongtax?post=456"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}