{"id":133602,"date":"2024-04-28T11:41:24","date_gmt":"2024-04-28T03:41:24","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/133602.html"},"modified":"2024-04-28T11:41:26","modified_gmt":"2024-04-28T03:41:26","slug":"php%e6%97%a5%e5%8e%86%e5%a6%82%e4%bd%95%e5%ae%9e%e7%8e%b0","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/133602.html","title":{"rendered":"php\u65e5\u5386\u5982\u4f55\u5b9e\u73b0"},"content":{"rendered":"<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24131735\/15473aaa-ab96-4dbb-8942-bc831f236876.webp\" alt=\"php\u65e5\u5386\u5982\u4f55\u5b9e\u73b0\" \/><\/p>\n<p><p>PHP\u65e5\u5386\u7684\u5b9e\u73b0\u4f9d\u8d56\u4e8e\u51e0\u4e2a\u6838\u5fc3\u6982\u5ff5\uff1a<strong>\u83b7\u53d6\u5f53\u524d\u65e5\u671f\u3001\u8ba1\u7b97\u6708\u4efd\u7684\u5929\u6570\u3001\u786e\u5b9a\u4e00\u4e2a\u6708\u7684\u7b2c\u4e00\u5929\u662f\u661f\u671f\u51e0<\/strong>\u3002PHP\u5185\u7f6e\u7684<code>date()<\/code>\u51fd\u6570\u3001<code>cal_days_in_month()<\/code>\u51fd\u6570\u548c<code>mktime()<\/code>\u51fd\u6570\u7b49\u662f\u5b9e\u73b0\u8fd9\u4e00\u529f\u80fd\u7684\u5173\u952e\u3002\u5176\u4e2d\uff0c<strong>\u8ba1\u7b97\u6708\u4efd\u7684\u5929\u6570<\/strong>\u662f\u5b9e\u73b0\u65e5\u5386\u7684\u57fa\u7840\uff0c\u56e0\u4e3a\u6211\u4eec\u9700\u8981\u77e5\u9053\u6bcf\u4e2a\u6708\u6709\u51e0\u5929\u6765\u6b63\u786e\u5730\u5c55\u793a\u6574\u4e2a\u6708\u7684\u65e5\u5386\u89c6\u56fe\u3002<\/p>\n<\/p>\n<p><p>\u4e3a\u4e86\u6df1\u5165\u7406\u89e3\uff0c\u6211\u4eec\u5148\u91cd\u70b9\u8ba8\u8bba\u5982\u4f55<strong>\u8ba1\u7b97\u4e00\u4e2a\u6708\u6709\u591a\u5c11\u5929<\/strong>\u3002PHP\u63d0\u4f9b\u4e86\u4e00\u4e2a\u975e\u5e38\u65b9\u4fbf\u7684\u51fd\u6570<code>cal_days_in_month()<\/code>\uff0c\u5b83\u9700\u8981\u4e09\u4e2a\u53c2\u6570\uff1a\u65e5\u5386\u7c7b\u578b\u3001\u6708\u4efd\u548c\u5e74\u4efd\u3002\u5bf9\u4e8e\u516c\u5386\uff0c\u65e5\u5386\u7c7b\u578b\u53c2\u6570\u4e3a<code>CAL_GREGORIAN<\/code>\u3002\u8fd9\u6837\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u5f88\u5bb9\u6613\u5730\u83b7\u53d6\u5230\u4efb\u4f55\u4e00\u4e2a\u6708\u7684\u5929\u6570\uff0c\u8fd9\u5bf9\u4e8e\u751f\u6210\u65e5\u5386\u6765\u8bf4\u662f\u5fc5\u4e0d\u53ef\u5c11\u7684\u4fe1\u606f\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u57fa\u672c\u6982\u5ff5<\/h3>\n<\/p>\n<p><p>\u5728\u6df1\u5165PHP\u65e5\u5386\u7684\u7f16\u7801\u5b9e\u73b0\u4e4b\u524d\uff0c\u4e86\u89e3\u6d89\u53ca\u7684\u4e00\u4e9b\u57fa\u672c\u6982\u5ff5\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002<\/p>\n<\/p>\n<p><h4>\u83b7\u53d6\u5f53\u524d\u65e5\u671f<\/h4>\n<\/p>\n<p><p>\u83b7\u53d6\u5f53\u524d\u65e5\u671f\u662f\u751f\u6210\u65e5\u5386\u7684\u51fa\u53d1\u70b9\u3002PHP\u7684<code>date()<\/code>\u51fd\u6570\u975e\u5e38\u9002\u7528\u4e8e\u8fd9\u4e00\u4efb\u52a1\u3002\u4f7f\u7528<code>date(&quot;Y&quot;)<\/code>\u53ef\u4ee5\u83b7\u5f97\u5f53\u524d\u7684\u5e74\u4efd\uff0c<code>date(&quot;m&quot;)<\/code>\u53ef\u4ee5\u83b7\u5f97\u5f53\u524d\u7684\u6708\u4efd\u3002\u8fd9\u4e3a\u6211\u4eec\u63d0\u4f9b\u4e86\u4e00\u4e2a\u57fa\u51c6\u70b9\uff0c\u4ece\u5f53\u524d\u65e5\u671f\u5f00\u59cb\u6784\u5efa\u65e5\u5386\u3002<\/p>\n<\/p>\n<p><h4>\u8ba1\u7b97\u6708\u4efd\u5929\u6570<\/h4>\n<\/p>\n<p><p>\u5982\u524d\u6240\u8ff0\uff0c<code>cal_days_in_month(CAL_GREGORIAN, $month, $year)<\/code>\u51fd\u6570\u5141\u8bb8\u6211\u4eec\u8ba1\u7b97\u51fa\u7ed9\u5b9a\u5e74\u4efd\u548c\u6708\u4efd\u7684\u5929\u6570\u3002\u8fd9\u4e2a\u51fd\u6570\u662f\u6784\u5efa\u65e5\u5386\u65f6\u7684\u5173\u952e\u6b65\u9aa4\uff0c\u56e0\u4e3a\u5b83\u51b3\u5b9a\u4e86\u65e5\u5386\u7684\u884c\u6570\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u51c6\u5907\u5de5\u4f5c<\/h3>\n<\/p>\n<p><p>\u5728\u7f16\u5199\u4ee3\u7801\u4e4b\u524d\uff0c\u5fc5\u987b\u505a\u4e00\u4e9b\u51c6\u5907\u5de5\u4f5c\uff0c\u5305\u62ec\u8bbe\u7f6e\u9ed8\u8ba4\u65f6\u533a\u548c\u5bfc\u5165\u5fc5\u9700\u7684\u51fd\u6570\u5e93\u7b49\u3002<\/p>\n<\/p>\n<p><h4>\u8bbe\u7f6e\u9ed8\u8ba4\u65f6\u533a<\/h4>\n<\/p>\n<p><p>\u4e3a\u4e86\u786e\u4fdd\u6211\u4eec\u64cd\u4f5c\u7684\u65e5\u671f\u548c\u65f6\u95f4\u4e0e\u7528\u6237\u7684\u5730\u7406\u4f4d\u7f6e\u4e00\u81f4\uff0c\u4f7f\u7528<code>date_default_timezone_set(&#039;your\/timezone&#039;)<\/code>\u6765\u8bbe\u7f6e\u5408\u9002\u7684\u65f6\u533a\u662f\u5f88\u6709\u5fc5\u8981\u7684\u3002<\/p>\n<\/p>\n<p><h4>\u5bfc\u5165\u51fd\u6570\u5e93<\/h4>\n<\/p>\n<p><p>\u867d\u7136PHP\u81ea\u5e26\u4e86\u4e30\u5bcc\u7684\u65e5\u671f\u548c\u65f6\u95f4\u51fd\u6570\uff0c\u4f46\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u53ef\u80fd\u9700\u8981\u81ea\u5b9a\u4e49\u51fd\u6570\u6765\u5904\u7406\u7279\u5b9a\u903b\u8f91\u3002\u4f8b\u5982\uff0c\u8ba1\u7b97\u67d0\u4e2a\u6708\u7684\u7b2c\u4e00\u5929\u662f\u661f\u671f\u51e0\uff0c\u6216\u8005\u751f\u6210\u65e5\u5386\u5e03\u5c40\u65f6\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u5b9e\u73b0\u65e5\u5386\u903b\u8f91<\/h3>\n<\/p>\n<p><p>\u5728\u638c\u63e1\u4e86\u57fa\u7840\u6982\u5ff5\u548c\u51c6\u5907\u5de5\u4f5c\u540e\uff0c\u4e0b\u4e00\u6b65\u5c31\u662f\u7528PHP\u4ee3\u7801\u6765\u5b9e\u73b0\u65e5\u5386\u7684\u903b\u8f91\u3002<\/p>\n<\/p>\n<p><h4>\u8ba1\u7b97\u6bcf\u6708\u7b2c\u4e00\u5929<\/h4>\n<\/p>\n<p><p>\u8981\u786e\u5b9a\u6708\u4efd\u7684\u7b2c\u4e00\u5929\u662f\u661f\u671f\u51e0\uff0c\u53ef\u4ee5\u4f7f\u7528PHP\u7684<code>mktime()<\/code>\u51fd\u6570\u548c<code>date(&quot;w&quot;)<\/code>\u3002\u901a\u8fc7\u5c06<code>mktime()<\/code>\u51fd\u6570\u7684\u53c2\u6570\u8bbe\u7f6e\u4e3a\u7ed9\u5b9a\u6708\u4efd\u7684\u7b2c\u4e00\u5929\uff0c\u5e76\u5c06\u7ed3\u679c\u4f20\u9012\u7ed9<code>date(&quot;w&quot;)<\/code>\uff0c\u6211\u4eec\u53ef\u4ee5\u5f97\u5230\u4e00\u4e2a\u4ece0\uff08\u4ee3\u8868\u661f\u671f\u5929\uff09\u52306\uff08\u4ee3\u8868\u661f\u671f\u516d\uff09\u7684\u6570\u5b57\u3002<\/p>\n<\/p>\n<p><h4>\u521b\u5efa\u65e5\u5386\u5e03\u5c40<\/h4>\n<\/p>\n<p><p>\u4e00\u65e6\u77e5\u9053\u4e86\u6708\u4efd\u7b2c\u4e00\u5929\u662f\u661f\u671f\u51e0\uff0c\u4ee5\u53ca\u8be5\u6708\u7684\u603b\u5929\u6570\uff0c\u4e0b\u4e00\u6b65\u5c31\u662f\u751f\u6210\u65e5\u5386\u7684\u5e03\u5c40\u3002\u8fd9\u901a\u5e38\u6d89\u53ca\u5faa\u73af\u548c\u6761\u4ef6\u903b\u8f91\uff0c\u4ee5\u786e\u4fdd\u6bcf\u5929\u88ab\u6b63\u786e\u653e\u7f6e\u5728\u65e5\u5386\u4e2d\u7684\u9002\u5f53\u4f4d\u7f6e\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u8fdb\u9636\u529f\u80fd<\/h3>\n<\/p>\n<p><h4>\u52a8\u6001\u6539\u53d8\u6708\u4efd<\/h4>\n<\/p>\n<p><p>\u63d0\u4f9b\u7528\u6237\u754c\u9762\u5141\u8bb8\u7528\u6237\u67e5\u770b\u4e0d\u540c\u6708\u4efd\u7684\u65e5\u5386\u662f\u5f88\u6709\u7528\u7684\u529f\u80fd\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7\u5728PHP\u811a\u672c\u4e2d\u589e\u52a0\u7b80\u5355\u7684\u903b\u8f91\u6765\u5b9e\u73b0\uff0c\u6839\u636e\u7528\u6237\u7684\u8f93\u5165\u52a8\u6001\u6539\u53d8\u5e74\u4efd\u548c\u6708\u4efd\u53c2\u6570\u3002<\/p>\n<\/p>\n<p><h4>\u8282\u5047\u65e5\u548c\u4e8b\u4ef6\u6807\u8bb0<\/h4>\n<\/p>\n<p><p>\u4e3a\u4e86\u4f7f\u65e5\u5386\u66f4\u52a0\u5b9e\u7528\uff0c\u53ef\u4ee5\u5728\u7279\u5b9a\u7684\u65e5\u671f\u6807\u8bb0\u8282\u5047\u65e5\u6216\u4e8b\u4ef6\u3002\u8fd9\u9700\u8981\u989d\u5916\u7684\u903b\u8f91\u6765\u68c0\u6d4b\u548c\u6807\u8bb0\u8fd9\u4e9b\u7279\u6b8a\u7684\u65e5\u671f\u3002<\/p>\n<\/p>\n<p><p>\u7efc\u4e0a\u6240\u8ff0\uff0cPHP\u65e5\u5386\u7684\u5b9e\u73b0\u6d89\u53ca\u5230\u4e86\u65e5\u671f\u548c\u65f6\u95f4\u7684\u5904\u7406\u3001\u5faa\u73af\u548c\u6761\u4ef6\u903b\u8f91\uff0c\u4ee5\u53ca\u7528\u6237\u754c\u9762\u7684\u4ea4\u4e92\u8bbe\u8ba1\u3002\u901a\u8fc7\u638c\u63e1\u4e0a\u8ff0\u6838\u5fc3\u6982\u5ff5\u53ca\u76f8\u5173\u7684PHP\u51fd\u6570\uff0c\u5373\u53ef\u6784\u5efa\u4e00\u4e2a\u57fa\u672c\u7684\u65e5\u5386\u5e94\u7528\uff0c\u5e76\u5728\u6b64\u57fa\u7840\u4e0a\u6839\u636e\u9700\u8981\u6269\u5c55\u66f4\u591a\u529f\u80fd\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p><strong>1. php\u65e5\u5386\u5e94\u7528\u7684\u5b9e\u73b0\u539f\u7406\u662f\u4ec0\u4e48\uff1f<\/strong><br \/>\nphp\u65e5\u5386\u7684\u5b9e\u73b0\u4e3b\u8981\u4f9d\u9760\u8ba1\u7b97\u65e5\u671f\u5e76\u5c06\u65e5\u671f\u4ee5\u7279\u5b9a\u7684\u683c\u5f0f\u663e\u793a\u51fa\u6765\u3002\u53ef\u4ee5\u4f7f\u7528PHP\u5185\u7f6e\u7684\u65e5\u671f\u548c\u65f6\u95f4\u51fd\u6570\u6765\u83b7\u53d6\u5f53\u524d\u65e5\u671f\u3001\u8ba1\u7b97\u4e0a\u4e00\u4e2a\u6708\u548c\u4e0b\u4e00\u4e2a\u6708\u7684\u65e5\u671f\uff0c\u7136\u540e\u4f7f\u7528\u5faa\u73af\u6765\u8f93\u51fa\u65e5\u5386\u4e2d\u7684\u6bcf\u4e00\u5929\uff0c\u5e76\u6839\u636e\u9700\u8981\u6837\u5f0f\u5316\u65e5\u671f\u7684\u5916\u89c2\u3002<\/p>\n<p><strong>2. \u5982\u4f55\u5728php\u65e5\u5386\u4e2d\u6dfb\u52a0\u81ea\u5b9a\u4e49\u4e8b\u4ef6\uff1f<\/strong><br \/>\n\u8981\u5728php\u65e5\u5386\u4e2d\u6dfb\u52a0\u81ea\u5b9a\u4e49\u4e8b\u4ef6\uff0c\u53ef\u4ee5\u5728\u6570\u636e\u5e93\u4e2d\u521b\u5efa\u4e00\u4e2a\u4e8b\u4ef6\u8868\uff0c\u5b58\u50a8\u6bcf\u4e2a\u4e8b\u4ef6\u7684\u65e5\u671f\u3001\u65f6\u95f4\u548c\u8be6\u7ec6\u4fe1\u606f\u3002\u7136\u540e\uff0c\u901a\u8fc7\u67e5\u8be2\u6570\u636e\u5e93\u83b7\u53d6\u4e8b\u4ef6\u6570\u636e\uff0c\u5e76\u5c06\u5b83\u4eec\u6dfb\u52a0\u5230\u76f8\u5e94\u7684\u65e5\u671f\u683c\u5b50\u4e2d\u3002\u53ef\u4ee5\u4f7f\u7528CSS\u6837\u5f0f\u6765\u6807\u8bb0\u7279\u5b9a\u7684\u4e8b\u4ef6\u7c7b\u578b\uff0c\u4f8b\u5982\u4e0d\u540c\u7684\u989c\u8272\u8868\u793a\u4e0d\u540c\u7684\u4e8b\u4ef6\u3002<\/p>\n<p><strong>3. \u5982\u4f55\u5b9e\u73b0php\u65e5\u5386\u7684\u54cd\u5e94\u5f0f\u8bbe\u8ba1\uff1f<\/strong><br \/>\n\u5b9e\u73b0php\u65e5\u5386\u7684\u54cd\u5e94\u5f0f\u8bbe\u8ba1\u53ef\u4ee5\u901a\u8fc7CSS\u5a92\u4f53\u67e5\u8be2\u6765\u5b9e\u73b0\uff0c\u6839\u636e\u8bbe\u5907\u7684\u5c4f\u5e55\u5927\u5c0f\u548c\u65b9\u5411\u5e94\u7528\u4e0d\u540c\u7684\u6837\u5f0f\u3002\u53ef\u4ee5\u4f7f\u7528\u54cd\u5e94\u5f0f\u7684CSS\u6846\u67b6\uff08\u5982Bootstrap\uff09\u6765\u7b80\u5316\u8fd9\u4e2a\u8fc7\u7a0b\uff0c\u4f7f\u65e5\u5386\u80fd\u591f\u5728\u4e0d\u540c\u5927\u5c0f\u7684\u8bbe\u5907\u4e0a\u81ea\u52a8\u9002\u5e94\u548c\u6392\u5217\u3002\u4f7f\u7528\u54cd\u5e94\u5f0f\u8bbe\u8ba1\u53ef\u4ee5\u786e\u4fdd\u65e5\u5386\u5728\u624b\u673a\u3001\u5e73\u677f\u548c\u684c\u9762\u7535\u8111\u4e0a\u7684\u663e\u793a\u6548\u679c\u90fd\u5f88\u597d\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"PHP\u65e5\u5386\u7684\u5b9e\u73b0\u4f9d\u8d56\u4e8e\u51e0\u4e2a\u6838\u5fc3\u6982\u5ff5\uff1a\u83b7\u53d6\u5f53\u524d\u65e5\u671f\u3001\u8ba1\u7b97\u6708\u4efd\u7684\u5929\u6570\u3001\u786e\u5b9a\u4e00\u4e2a\u6708\u7684\u7b2c\u4e00\u5929\u662f\u661f\u671f\u51e0\u3002PHP\u5185\u7f6e\u7684da [&hellip;]","protected":false},"author":3,"featured_media":133608,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/133602"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=133602"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/133602\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/133608"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=133602"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=133602"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=133602"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}