{"id":461,"date":"2025-06-10T20:46:43","date_gmt":"2025-06-10T12:46:43","guid":{"rendered":"https:\/\/www.zhaozhao123.cn\/php\/php-application-manual\/jcyy\/461.html"},"modified":"2025-06-10T20:46:43","modified_gmt":"2025-06-10T12:46:43","slug":"%e5%a6%82%e4%bd%95%e6%a3%80%e6%9f%a5%e6%97%a5%e6%9c%9f%e6%98%af%e5%90%a6%e5%9c%a8%e6%9c%89%e6%95%88%e6%a0%bc%e5%bc%8f%e4%b8%ad","status":"publish","type":"my1js","link":"https:\/\/www.zhaozhao123.cn\/php\/my1js\/461.html","title":{"rendered":"\u5982\u4f55\u68c0\u67e5\u65e5\u671f\u662f\u5426\u5728\u6709\u6548\u683c\u5f0f\u4e2d"},"content":{"rendered":"<p><body><\/p>\n<p>&#22788;&#29702;&#26085;&#26399;&#22312;&#35768;&#22810;PHP&#24212;&#29992;&#31243;&#24207;&#20013;&#26159;&#19968;&#39033;&#24120;&#35265;&#30340;&#20219;&#21153;&#65292;&#26080;&#35770;&#26159;&#31649;&#29702;&#29992;&#25143;&#36755;&#20837;&#12289;&#35299;&#26512;&#25991;&#20214;&#36824;&#26159;&#19982;&#25968;&#25454;&#24211;&#20132;&#20114;&#12290;&#22240;&#27492;&#65292;&#22312;&#36827;&#34892;&#20219;&#20309;&#25805;&#20316;&#20043;&#21069;&#30830;&#20445;&#26085;&#26399;&#23383;&#31526;&#20018;&#26684;&#24335;&#27491;&#30830;&#26159;&#33267;&#20851;&#37325;&#35201;&#30340;&#65292;&#36825;&#21487;&#20197;&#38450;&#27490;&#38169;&#35823;&#24182;&#20445;&#35777;&#25968;&#25454;&#23436;&#25972;&#24615;&#12290;&#22312;&#36825;&#31687;&#25991;&#31456;&#20013;&#65292;&#25105;&#20204;&#23558;&#25506;&#35752;&#20960;&#31181;&#29992;&#20110;&#39564;&#35777;PHP&#26085;&#26399;&#26684;&#24335;&#30340;&#26041;&#27861;&#65292;&#21253;&#25324;&#20351;&#29992;&#20869;&#32622;&#20989;&#25968;&#12289;&#27491;&#21017;&#34920;&#36798;&#24335;&#21644;DateTime&#31867;&#12290;<\/p>\n<h2>&#29702;&#35299;&#26085;&#26399;&#26684;&#24335;<\/h2>\n<p>&#22312;&#39564;&#35777;&#26085;&#26399;&#20043;&#21069;&#65292;&#20102;&#35299;&#20320;&#25171;&#31639;&#20351;&#29992;&#30340;&#26085;&#26399;&#26684;&#24335;&#38750;&#24120;&#37325;&#35201;&#12290;&#24120;&#35265;&#30340;&#26085;&#26399;&#26684;&#24335;&#21253;&#25324;&ldquo;Y-m-d&rdquo;&#65288;&#20363;&#22914;&#65292;&ldquo;2023-03-15&rdquo;&#65289;&#30340;&#22269;&#38469;&#19978;&#19979;&#25991;&#21644;&ldquo;m\/d\/Y&rdquo;&#65288;&#20363;&#22914;&#65292;&ldquo;03\/15\/2023&rdquo;&#65289;&#30340;&#32654;&#22269;&#19978;&#19979;&#25991;&#31561;&#12290;PHP&#25552;&#20379;&#20102;&#35768;&#22810;&#20869;&#32622;&#20989;&#25968;&#26469;&#25903;&#25345;&#21508;&#31181;&#26085;&#26399;&#26684;&#24335;&#12290;<\/p>\n<h2>&#20351;&#29992;checkdate()&#20989;&#25968;<\/h2>\n<p>&#35813;&#20989;&#25968;checkdate()&#26159;&#19968;&#31181;&#31616;&#21333;&#30340;&#26041;&#27861;&#65292;&#29992;&#20110;&#26681;&#25454;&#26684;&#37324;&#39640;&#21033;&#21382;&#26816;&#26597;&#25552;&#20379;&#30340;&#26085;&#26399;&#26159;&#21542;&#26377;&#25928;&#12290;&#23427;&#25509;&#21463;&#19977;&#20010;&#21442;&#25968;&#65306;&#26376;&#20221;&#12289;&#26085;&#21644;&#24180;&#12290;<\/p>\n<pre><code>$month = 3;\r\n$day = 15;\r\n$year = 2023;\r\n\r\nif (checkdate($month, $day, $year)) {\r\n    echo 'The date is valid.';\r\n} else {\r\n    echo 'The date is not valid.';\r\n}\r\n<\/code><\/pre>\n<p>&#36825;&#20010;&#21151;&#33021;&#24456;&#31616;&#21333;&#65292;&#20294;&#20320;&#38656;&#35201;&#22312;&#36827;&#34892;&#39564;&#35777;&#20043;&#21069;&#20808;&#23558;&#26085;&#26399;&#32452;&#20214;&#20998;&#31163;&#24320;&#26469;&#12290;<\/p>\n<h2>&#20351;&#29992;DateTime::createFromFormat<\/h2>\n<p>DateTime&#31867;&#25552;&#20379;&#20102;&#19968;&#20010;createFromFormat&#26041;&#27861;&#65292;&#35813;&#26041;&#27861;&#23581;&#35797;&#20351;&#29992;&#29305;&#23450;&#30340;&#26684;&#24335;&#35299;&#26512;&#23383;&#31526;&#20018;&#12290;&#22914;&#26524;&#35299;&#26512;&#25104;&#21151;&#65292;&#21017;&#36820;&#22238;&#19968;&#20010;DateTime&#23545;&#35937;&#65307;&#21542;&#21017;&#36820;&#22238;false&#12290;&#20363;&#22914;&#65306;<\/p>\n<pre><code>$dateString = '2023-03-15';\r\n$format = 'Y-m-d';\r\n$date = DateTime::createFromFormat($format, $dateString);\r\n\r\nif ($date &amp;&amp; $date-&gt;format($format) == $dateString) {\r\n    echo 'The date is valid.';\r\n} else {\r\n    echo 'The date is not valid.';\r\n}\r\n<\/code><\/pre>\n<p>&#36825;&#31181;&#26041;&#27861;&#22312;&#39564;&#35777;&#26684;&#24335;&#26041;&#38754;&#34920;&#29616;&#21331;&#36234;&#65292;&#19988;&#33021;&#22815;&#22788;&#29702;&#30001;&#25552;&#20379;&#30340;&#26684;&#24335;&#23383;&#31526;&#20018;&#30830;&#23450;&#30340;&#22810;&#31181;&#26085;&#26399;&#27169;&#24335;&#12290;<\/p>\n<h2>&#26085;&#26399;&#39564;&#35777;&#30340;&#27491;&#21017;&#34920;&#36798;&#24335;<\/h2>\n<p>&#20026;&#20102;&#26356;&#22909;&#22320;&#25511;&#21046;&#26085;&#26399;&#39564;&#35777;&#65292;&#25110;&#32773;&#22312;&#22788;&#29702;&#38750;&#26631;&#20934;&#26085;&#26399;&#26684;&#24335;&#26102;&#65292;&#27491;&#21017;&#34920;&#36798;&#24335;&#25552;&#20379;&#20102;&#19968;&#20010;&#24378;&#22823;&#30340;&#26367;&#20195;&#26041;&#26696;&#12290;&#36825;&#37324;&#26377;&#19968;&#20010;&#21305;&#37197;&lsquo;Y-m-d&rsquo;&#26684;&#24335;&#26085;&#26399;&#30340;&#31034;&#20363;&#27491;&#21017;&#34920;&#36798;&#24335;&#65306;<\/p>\n<pre><code>$dateString = '2023-03-15';\r\n$pattern = '\/^d{4}-d{2}-d{2}$\/';\r\n\r\nif (preg_match($pattern, $dateString)) {\r\n    $parts = explode('-', $dateString);\r\n    \r\n    if (checkdate($parts[1], $parts[2], $parts[0])) {\r\n        echo 'The date is valid.';\r\n    } else {\r\n        echo 'The date is not valid.';\r\n    }\r\n} else {\r\n    echo 'The format of the date is not valid.';\r\n}\r\n<\/code><\/pre>\n<p>&#36825;&#20010;&#31034;&#20363;&#39318;&#20808;&#26816;&#26597;&#26085;&#26399;&#26159;&#21542;&#31526;&#21512;&#39044;&#26399;&#30340;&#27169;&#24335;&#65292;&#28982;&#21518;&#39564;&#35777;&#26085;&#26399;&#20013;&#30340;&#21508;&#20010;&#37096;&#20998;&#12290;<\/p>\n<h2>&#22788;&#29702;&#22810;&#31181;&#26684;&#24335;<\/h2>\n<p>&#22312;&#26576;&#20123;&#22330;&#26223;&#19979;&#65292;&#24744;&#21487;&#33021;&#38656;&#35201;&#39564;&#35777;&#36328;&#36234;&#22810;&#20010;&#26684;&#24335;&#30340;&#26085;&#26399;&#12290;&#21487;&#20197;&#36890;&#36807;&#23581;&#35797;&#21019;&#24314;&#20855;&#26377;&#19981;&#21516;&#26684;&#24335;&#30340;DateTime&#23545;&#35937;&#25110;&#20351;&#29992;&#19968;&#31995;&#21015;&#27491;&#21017;&#34920;&#36798;&#24335;&#26469;&#23454;&#29616;&#36825;&#19968;&#28857;&#12290;&#20851;&#38190;&#22312;&#20110;&#30830;&#20445;&#39564;&#35777;&#36923;&#36753;&#33021;&#22815;&#35206;&#30422;&#25152;&#26377;&#21487;&#33021;&#30340;&#26684;&#24335;&#65292;&#36991;&#20813;&#20135;&#29983;&#20551;&#38451;&#24615;&#12290;<\/p>\n<h2>&#22788;&#29702;&#36793;&#32536;&#24773;&#20917;&#12290;<\/h2>\n<p>&#38656;&#35201;&#27880;&#24847;&#30340;&#26159;&#65292;&#26085;&#26399;&#21487;&#33021;&#26377;&#36793;&#32536;&#24773;&#20917;&#23548;&#33268;&#24494;&#22937;&#30340;&#38169;&#35823;&#12290;&#20363;&#22914;&#65292;&#38384;&#24180;&#12289;&#26102;&#21306;&#12289;&#22799;&#20196;&#26102;&#21464;&#21160;&#21644;&#21382;&#21490;&#19978;&#30340;&#21382;&#27861;&#25913;&#38761;&#37117;&#21487;&#33021;&#24433;&#21709;&#26085;&#26399;&#39564;&#35777;&#12290;&#30830;&#20445;&#23545;&#24744;&#30340;&#39564;&#35777;&#20195;&#30721;&#36827;&#34892;&#24443;&#24213;&#27979;&#35797;&#65292;&#21253;&#25324;&#36825;&#20123;&#36793;&#32536;&#24773;&#20917;&#12290;<\/p>\n<h2>&#32467;&#35770;&#12290;<\/h2>\n<p>&#27491;&#30830;&#26085;&#26399;&#39564;&#35777;&#22312;PHP&#24212;&#29992;&#31243;&#24207;&#20013;&#33267;&#20851;&#37325;&#35201;&#12290;&#20170;&#22825;&#65292;&#25105;&#20204;&#24050;&#32463;&#35752;&#35770;&#20102;&#20960;&#31181;&#23454;&#29616;&#27492;&#21151;&#33021;&#30340;&#26041;&#27861;&#65306;&#20351;&#29992;checkdate()&#20989;&#25968;&#12289;DateTime&#31867;&#21644;&#27491;&#21017;&#34920;&#36798;&#24335;&#12290;&#27599;&#20010;&#26041;&#27861;&#37117;&#26377;&#20854;&#20248;&#21183;&#65292;&#21487;&#20197;&#26681;&#25454;&#39033;&#30446;&#30340;&#20855;&#20307;&#38656;&#27714;&#36873;&#25321;&#20854;&#20013;&#19968;&#31181;&#12290;&#22987;&#32456;&#35201;&#22788;&#29702;&#36793;&#32536;&#24773;&#20917;&#24182;&#29992;&#21508;&#31181;&#26085;&#26399;&#22330;&#26223;&#27979;&#35797;&#20195;&#30721;&#65292;&#20197;&#30830;&#20445;&#20934;&#30830;&#24615;&#24182;&#25552;&#39640;&#21487;&#38752;&#24615;&#12290;<\/p>\n<p>&#36981;&#24490;&#26412;&#25945;&#31243;&#20013;&#30340;&#26368;&#20339;&#23454;&#36341;&#21644;&#31034;&#20363;&#65292;&#20320;&#24212;&#35813;&#33021;&#22815;&#24456;&#22909;&#22320;&#22788;&#29702;PHP&#24212;&#29992;&#31243;&#24207;&#20013;&#30340;&#26085;&#26399;&#39564;&#35777;&#38382;&#39064;&#12290;&#22312;&#24320;&#21457;&#36807;&#31243;&#20013;&#65292;&#35831;&#35760;&#20303;&#36873;&#25321;&#36866;&#21512;&#24037;&#20316;&#30340;&#27491;&#30830;&#24037;&#20855;&#65292;&#32771;&#34385;&#21040;&#24744;&#30340;&#26085;&#26399;&#25968;&#25454;&#30340;&#22797;&#26434;&#24615;&#21644;&#22810;&#26679;&#24615;&#12290;<\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#22788;&#29702;&#26085;&#26399;&#22312;&#35768;&#22810;PHP&#24212;&#29992;&#31243;&#24207;&#20013;&#26159;&#19968;&#39033;&#24120;&#35265;&#30340;&#20219;&#038;#211..<\/p>\n","protected":false},"author":1,"featured_media":0,"menu_order":0,"template":"","meta":{"_acf_changed":false},"tags":[],"my1js2nav":[38],"tuisongtax":[],"class_list":["post-461","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\/461","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=461"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/tags?post=461"},{"taxonomy":"my1js2nav","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js2nav?post=461"},{"taxonomy":"tuisongtax","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/tuisongtax?post=461"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}