{"id":467,"date":"2025-06-10T20:51:59","date_gmt":"2025-06-10T12:51:59","guid":{"rendered":"https:\/\/www.zhaozhao123.cn\/php\/php-application-manual\/jcyy\/467.html"},"modified":"2025-06-10T20:51:59","modified_gmt":"2025-06-10T12:51:59","slug":"php%ef%bc%9a%e5%a6%82%e4%bd%95%e4%bb%8e%e6%97%a5%e6%9c%9f%e6%97%b6%e9%97%b4%e4%b8%ad%e8%8e%b7%e5%8f%96%e6%97%a5%e6%9c%9f%e9%83%a8%e5%88%86","status":"publish","type":"my1js","link":"https:\/\/www.zhaozhao123.cn\/php\/my1js\/467.html","title":{"rendered":"PHP\uff1a\u5982\u4f55\u4ece\u65e5\u671f\u65f6\u95f4\u4e2d\u83b7\u53d6\u65e5\u671f\u90e8\u5206"},"content":{"rendered":"<p><body><\/p>\n<h2>&#27010;&#35272;<\/h2>\n<p>&#22788;&#29702;&#26085;&#26399;&#21644;&#26102;&#38388;&#22312;PHP&#24320;&#21457;&#20013;&#26159;&#19968;&#39033;&#24120;&#35265;&#30340;&#20219;&#21153;&#12290;&#26377;&#26102;&#65292;&#19968;&#20010;&#24320;&#21457;&#32773;&#21487;&#33021;&#38656;&#35201;&#20174;DateTime&#23545;&#35937;&#20013;&#25552;&#21462;&#20165;&#21253;&#21547;&#26085;&#26399;&#30340;&#37096;&#20998;&#12290;&#26412;&#25945;&#31243;&#28436;&#31034;&#20102;&#22914;&#20309;&#26377;&#25928;&#22320;&#25552;&#21462;&#21482;&#21253;&#21547;&#26085;&#26399;&#37096;&#20998;&#30340;&#20869;&#23481;&#12290;<\/p>\n<h2>&#22312;PHP&#20013;&#29702;&#35299;DateTime&#31867;&#26159;&#38750;&#24120;&#37325;&#35201;&#30340;&#65292;&#22240;&#20026;&#23427;&#20801;&#35768;&#20320;&#22312;&#20195;&#30721;&#20013;&#21019;&#24314;&#21644;&#25805;&#20316;&#26085;&#26399;&#21644;&#26102;&#38388;&#12290;<\/h2>\n<p>PHP&#30340;DateTime&#31867;&#25552;&#20379;&#20102;&#22788;&#29702;&#26085;&#26399;&#21644;&#26102;&#38388;&#30340;&#24378;&#22823;&#21151;&#33021;&#12290;&#23427;&#25903;&#25345;&#38754;&#21521;&#23545;&#35937;&#30340;&#25805;&#20316;&#65292;&#21487;&#20197;&#23454;&#20363;&#21270;&#20197;&#34920;&#31034;&#29305;&#23450;&#30340;&#26102;&#38388;&#28857;&#12290;<\/p>\n<pre><code>$dateTime = new DateTime('2023-03-15 08:30:00');\n<\/code><\/pre>\n<p>&#19968;&#26086;&#21019;&#24314;&#20102;&#19968;&#20010;DateTime&#23545;&#35937;&#65292;&#23601;&#21487;&#20197;&#20197;&#22810;&#31181;&#26041;&#24335;&#33719;&#21462;&#26085;&#26399;&#37096;&#20998;&#12290;&#35753;&#25105;&#20204;&#20174;&#26368;&#31616;&#21333;&#30340;&#20837;&#25163;&#65292;&#36880;&#27493;&#36807;&#28193;&#21040;&#26356;&#20855;&#20307;&#30340;&#22330;&#26223;&#12290;<\/p>\n<h2>&#20351;&#29992;<code>format<\/code>&#26041;&#27861;<\/h2>\n<p>&#23545;&#19981;&#36215;&#65292;&#25105;&#26080;&#27861;&#29702;&#35299;&#24744;&#30340;&#38382;&#39064;&#12290;<code>format<\/code>&#26041;&#27861;&#26159;&#26368;&#30452;&#25509;&#25552;&#21462;&#26085;&#26399;&#30340;&#26041;&#24335;&#12290;&#23427;&#20801;&#35768;&#26681;&#25454;&#25552;&#20379;&#30340;&#26684;&#24335;&#23383;&#31526;&#23558;&#26085;&#26399;&#21644;&#26102;&#38388;&#26684;&#24335;&#21270;&#20026;&#23383;&#31526;&#20018;&#12290;<\/p>\n<pre><code>$date = $dateTime-&gt;format('Y-m-d');\n<\/code><\/pre>\n<p>&#36825;&#23558;&#29983;&#25104;&#19968;&#20010;&#20165;&#21253;&#21547;&#24180;&#12289;&#26376;&#21644;&#26085;&#30340;&#23383;&#31526;&#20018;&#12290;&#20294;&#22914;&#26524;&#25105;&#20204;&#36935;&#21040;&#19981;&#21516;&#30340;&#26684;&#24335;&#25110;&#35201;&#27714;&#21602;&#65311;&#35753;&#25105;&#20204;&#28145;&#20837;&#25506;&#35752;&#19968;&#19979;&#12290;<\/p>\n<h2>&#22788;&#29702;&#26102;&#21306;&#38382;&#39064;<\/h2>\n<p>&#26102;&#21306;&#22312;&#25805;&#20316;DateTime&#23545;&#35937;&#26102;&#21487;&#20197;&#21457;&#25381;&#37325;&#35201;&#20316;&#29992;&#12290;&#20026;&#20102;&#30830;&#20445;&#26085;&#26399;&#25552;&#21462;&#21040;&#27491;&#30830;&#30340;&#26102;&#21306;&#65292;&#21487;&#20197;&#22312;&#23545;&#35937;&#21019;&#24314;&#26102;&#25110;&#35843;&#29992;&#20043;&#21069;&#35774;&#32622;&#26102;&#21306;&#12290;<code>format<\/code>&#26041;&#27861;&#65306;<\/p>\n<pre><code>$dateTime = new DateTime('now', new DateTimeZone('America\/New_York'));\n$date = $dateTime-&gt;format('Y-m-d');\n<\/code><\/pre>\n<p>&#22312;&#26410;&#25351;&#23450;&#26102;&#21306;&#30340;&#24773;&#20917;&#19979;&#65292;PHP &#20351;&#29992;&#37197;&#32622;&#25991;&#20214; php.ini &#20013;&#35774;&#32622;&#30340;&#40664;&#35748;&#26102;&#21306;&#12290;<\/p>\n<h2>&#20351;&#29992;<code>DateTime::createFromFormat<\/code><\/h2>\n<p>&#22312;&#22788;&#29702;&#21508;&#31181;&#26085;&#26399;&#23383;&#31526;&#20018;&#26684;&#24335;&#26102;&#65292;<code>DateTime::createFromFormat<\/code>&#21464;&#24471;&#26377;&#29992;&#12290;&#27492;&#38745;&#24577;&#26041;&#27861;&#26681;&#25454;&#25351;&#23450;&#30340;&#26684;&#24335;&#35299;&#26512;&#26085;&#26399;-&#26102;&#38388;&#23383;&#31526;&#20018;&#65306;<\/p>\n<pre><code>$dateTime = DateTime::createFromFormat('j-M-Y', '15-Mar-2023');\n$date = $dateTime-&gt;format('Y-m-d');\n<\/code><\/pre>\n<p>&#36825;&#36824;&#21487;&#20197;&#25552;&#21462;&#26085;&#26399;&#37096;&#20998;&#65292;&#26080;&#35770;&#21021;&#22987;&#30340;&#26085;&#26399;&#26102;&#38388;&#23383;&#31526;&#20018;&#26684;&#24335;&#22914;&#20309;&#12290;<\/p>\n<h2>&#22788;&#29702;SQL&#26085;&#26399;&#26102;&#38388;&#26684;&#24335;<\/h2>\n<p>&#22914;&#26524;&#22312;&#22788;&#29702;SQL&#25968;&#25454;&#24211;&#26102;&#65292;&#21487;&#33021;&#20250;&#33719;&#21462;&#21040;&#20197;SQL&#26684;&#24335;&#34920;&#31034;&#30340;&#26085;&#26399;&#26102;&#38388;&#12290;PHP&#23545;&#27492;&#26684;&#24335;&#38750;&#24120;&#21451;&#22909;&#65306;<\/p>\n<pre><code>$sqlDateTime = '2023-03-15 08:30:00';\n$dateTime = new DateTime($sqlDateTime);\n$date = $dateTime-&gt;format('Y-m-d');\n<\/code><\/pre>\n<p>&#36825;&#31934;&#30830;&#22320;&#21435;&#25481;&#26102;&#38388;&#37096;&#20998;&#65292;&#30041;&#19979;&#19968;&#20010;&#24178;&#20928;&#30340;&#26085;&#26399;&#12290;<\/p>\n<h2>&#19982;&#24403;&#21069;&#26102;&#38388;&#24037;&#20316;<\/h2>\n<p>&#35201;&#20174;&#24403;&#21069;&#26102;&#38388;&#25552;&#21462;&#26085;&#26399;&#37096;&#20998;&#65292;&#21482;&#38656;&#21019;&#24314;&#19968;&#20010;&#19981;&#20256;&#36882;&#20219;&#20309;&#21442;&#25968;&#30340;&#26032;DateTime&#23545;&#35937;&#24182;&#26684;&#24335;&#21270;&#23427;&#21363;&#21487;&#65306;<\/p>\n<pre><code>$dateTime = new DateTime();\n$date = $dateTime-&gt;format('Y-m-d');\n<\/code><\/pre>\n<h2>&#21033;&#29992;<code>DateTimeImmutable<\/code><\/h2>\n<p>&#24403;&#24212;&#29992;&#31243;&#24207;&#19981;&#24212;&#20462;&#25913;&#21407;&#22987;&#30340;DateTime&#23545;&#35937;&#26102;&#65292;<code>DateTimeImmutable<\/code>&#21487;&#20197;&#20351;&#29992;&#30340;&#65306;<\/p>\n<pre><code>$immutable = new DateTimeImmutable('2023-03-15 08:30:00');\n$date = $immutable-&gt;format('Y-m-d');\n<\/code><\/pre>\n<p>&#36825;&#20445;&#35777;&#20102;&#20854;&#20182;&#25805;&#20316;&#21518;&#65292;&#21407;&#22987;&#23545;&#35937;&#19981;&#21464;&#12290;<\/p>\n<h2>&#39640;&#32423;&#26684;&#24335;&#21270;&#26041;&#27861;&#12290;<code>IntlDateFormatter<\/code><\/h2>\n<p>&#20026;&#20102;&#36827;&#34892;&#26412;&#22320;&#21270;&#65292;&#20320;&#38656;&#35201;&#25552;&#20379;&#26356;&#22810;&#20449;&#24687;&#12290;&#35831;&#21578;&#35785;&#25105;&#26356;&#22810;&#32454;&#33410;&#12290;<code>IntlDateFormatter<\/code>&#24456;&#26041;&#20415;&#65292;&#25552;&#20379;&#26412;&#22320;&#21270;&#26085;&#26399;&#26684;&#24335;&#65306;<\/p>\n<pre><code>$formatter = new IntlDateFormatter(\n    'en_US',\n    IntlDateFormatter::FULL,\n    IntlDateFormatter::NONE\n);\n$date = $formatter-&gt;format(new DateTime('2023-03-15 08:30:00'));\n<\/code><\/pre>\n<p>&#36825;&#19981;&#20165;&#25552;&#21462;&#26085;&#26399;&#65292;&#36824;&#25353;&#29031;&#32654;&#22269;&#33521;&#35821;&#26684;&#24335;&#36827;&#34892;&#26684;&#24335;&#21270;&#12290;<\/p>\n<h2>&#20351;&#29992;&#12290;<code>date()<\/code>&#21151;&#33021;<\/h2>\n<p>&#38500;&#20102;DateTime&#23545;&#35937;&#65292;PHP&#30340;<code>date()<\/code>&#20989;&#25968;&#21487;&#20197;&#19982;&#20854;&#20182;&#20989;&#25968;&#21327;&#21516;&#24037;&#20316;&#26469;&#23436;&#25104;&#30456;&#21516;&#30340;&#20219;&#21153;&#12290;<code>strtotime()<\/code>&#65306;<\/p>\n<pre><code>$date = date('Y-m-d', strtotime('2023-03-15 08:30:00'));\n<\/code><\/pre>\n<p>&#36825;&#26159;&#26356;&#38750;&#38754;&#21521;&#23545;&#35937;&#30340;&#65292;&#20294;&#20173;&#28982;&#26377;&#25928;&#65292;&#29305;&#21035;&#26159;&#22312;&#36951;&#30041;&#20195;&#30721;&#24211;&#20013;&#12290;<\/p>\n<h2>&#32467;&#35770;<\/h2>\n<p>&#26412;&#25945;&#31243;&#28085;&#30422;&#20102;&#22312;PHP&#20013;&#25552;&#21462;&#20165;&#26085;&#26399;&#37096;&#20998;&#30340;&#22810;&#31181;&#26041;&#27861;&#65292;&#36866;&#29992;&#20110;&#26032;&#25163;&#21644;&#26377;&#32463;&#39564;&#30340;&#24320;&#21457;&#20154;&#21592;&#12290;&#23454;&#26045;&#36825;&#20123;&#25216;&#24039;&#21487;&#20197;&#30830;&#20445;&#31934;&#30830;&#24615;&#21644;&#19982;&#19981;&#21516;&#26684;&#24335;&#21450;&#38656;&#27714;&#20860;&#23481;&#24615;&#12290;<\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#27010;&#35272; &#22788;&#29702;&#26085;&#26399;&#21644;&#26102;&#38388;&#22312;PHP&#24320;&#21457;&#20013;&#26159;&#19968;&#39033;&#24120;&#35265;&#30340;&#038;#20..<\/p>\n","protected":false},"author":1,"featured_media":0,"menu_order":0,"template":"","meta":{"_acf_changed":false},"tags":[],"my1js2nav":[38],"tuisongtax":[],"class_list":["post-467","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\/467","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=467"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/tags?post=467"},{"taxonomy":"my1js2nav","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js2nav?post=467"},{"taxonomy":"tuisongtax","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/tuisongtax?post=467"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}