{"id":796,"date":"2023-04-20T10:34:25","date_gmt":"2023-04-20T02:34:25","guid":{"rendered":"http:\/\/blog.nonot.cn\/?p=796"},"modified":"2024-07-08T12:43:35","modified_gmt":"2024-07-08T04:43:35","slug":"php%e8%ae%a1%e7%ae%97%e4%b8%a4%e4%b8%aa%e6%97%a5%e6%9c%9f%e7%9b%b8%e5%b7%ae%e7%9a%84%e5%a4%a9%e6%95%b0%e6%96%b9%e6%b3%95%e8%af%a6%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/blog.nonot.cn\/index.php\/2023\/04\/20\/php%e8%ae%a1%e7%ae%97%e4%b8%a4%e4%b8%aa%e6%97%a5%e6%9c%9f%e7%9b%b8%e5%b7%ae%e7%9a%84%e5%a4%a9%e6%95%b0%e6%96%b9%e6%b3%95%e8%af%a6%e8%a7%a3\/","title":{"rendered":"PHP\u8ba1\u7b97\u4e24\u4e2a\u65e5\u671f\u76f8\u5dee\u7684\u5929\u6570\u65b9\u6cd5\u8be6\u89e3"},"content":{"rendered":"<pre><code class=\"language-php\">\/**\n * \u6c42\u4e24\u4e2a\u65e5\u671f\u4e4b\u95f4\u76f8\u5dee\u7684\u5929\u6570\n * (\u9488\u5bf91970\u5e741\u67081\u65e5\u4e4b\u540e\uff0c\u6c42\u4e4b\u524d\u53ef\u4ee5\u91c7\u7528\u6cf0\u52d2\u516c\u5f0f)\n * @param string $date1\n * @param string $date2\n * @return number\n *\/\nfunction diff_date($date1, $date2){\n    if($date1&gt;$date2){\n        $startTime = strtotime($date1);\n    $endTime = strtotime($date2);\n    }else{\n    $startTime = strtotime($date2);\n    $endTime = strtotime($date1);\n    }\n    $diff = $startTime-$endTime;\n    $day = $diff\/86400;\n    return intval($day);\n\uff5d<\/code><\/pre>\n<p>\u6d4b\u8bd5\u7ed3\u679c\uff1a<\/p>\n<pre><code class=\"language-php\">$date1 = '2017-03-15 00:00:00';\n$date2 = '2017-03-16 00:00:00';\necho diff_date($date1,$date2);\n\/\/\u8f93\u51fa\uff1a1\n \n$date1 = '2017-03-15 00:00:01';\n$date2 = '2017-03-16 00:00:00';\necho diff_date($date1,$date2);\n\/\/\u8f93\u51fa\uff1a0\n \n$date1 = '2017-03-15 00:00:01';\n$date2 = '2017-03-16 00:00:02';\necho diff_date($date1,$date2);\n\/\/\u8f93\u51fa\uff1a0<\/code><\/pre>\n<p>\u603b\u7ed3<\/p>\n<p>\u6b64\u65b9\u6cd5\u4e3a24\u5c0f\u65f6\u5236\uff0c\u4e5f\u5c31\u662f\u8bf4\u65f6\u95f4\u5fc5\u987b\u6ee124\u5c0f\u65f6\u624d\u7b97\u4e00\u5929<\/p>\n<p>\u6b64\u65b9\u6cd5\u548c\u4e0a\u9762\u7684\u7c7b\u4f3c\uff0c\u53ea\u4e0d\u8fc7\u662f\u4f20\u5165\u7684\u53c2\u6570\u76f4\u63a5\u662f\u65f6\u95f4\u6233<\/p>\n<pre><code class=\"language-php\">\/**\n * \u6c42\u4e24\u4e2a\u65e5\u671f\u4e4b\u95f4\u76f8\u5dee\u7684\u5929\u6570\n * (\u9488\u5bf91970\u5e741\u67081\u65e5\u4e4b\u540e\uff0c\u6c42\u4e4b\u524d\u53ef\u4ee5\u91c7\u7528\u6cf0\u52d2\u516c\u5f0f)\n * @param string $time1\n * @param string $time2\n * @return number\n *\/\n \nfunction diff_time($time1,$time2){\n    if($time1 &lt; $time2){\n    $time0 = $time1;\n    $time1 = $time2;\n    $time2 = $time0;\n    }\n    $diff = ($time1-$time2)\/86400;\n    return intval($diff);\n}<\/code><\/pre>\n<p>\u9644\u52a0\u5b66\u4e60<\/p>\n<p>PHP\u4e2d\u8ba1\u7b97\u4e24\u4e2a\u65f6\u95f4\u76f8\u5dee\u7684\u5929\u6570\u3001\u5c0f\u65f6\u6570\u3001\u5206\u949f\u6570\u3001\u79d2\u6570\u4e0d\u5982\u5176\u5b83\u8bed\u8a00\u65b9\u4fbf\uff0c\u4f46\u641e\u6e05\u4e86PHP\u4e2d\u65f6\u95f4\u7684\u8868\u793a\u65b9\u6cd5\u540e\u4e5f\u5f88\u7b80\u5355\u3002\u672c\u6587\u7ae0\u5411\u5927\u5bb6\u8bb2\u89e3php\u5982\u4f55\u8ba1\u7b97\u65f6\u95f4\u76f8\u5dee\u3002\u9700\u8981\u7684\u7801\u519c\u53ef\u4ee5\u53c2\u8003\u4e00\u4e0b<\/p>\n<pre class=\"\"><code class=\"language-php\">$date1 = '2017-03-15 00:00:01';\n$date2 = '2017-03-15 00:00:00';\n \n$date=floor((strtotime($date1)-strtotime($date2))\/86400);\necho \"\u76f8\u5dee\u5929\u6570\uff1a\".$date.\"\u5929\n\n\";\n \n$hour=floor((strtotime($date1)-strtotime($date2))%86400\/3600);\necho \"\u76f8\u5dee\u5c0f\u65f6\u6570\uff1a\".$hour.\"\u5c0f\u65f6\n\n\";\n \n$minute=floor((strtotime($date1)-strtotime($date2))%86400\/60);\necho \"\u76f8\u5dee\u5206\u949f\u6570\uff1a\".$minute.\"\u5206\u949f\n\n\";\n \n$second=floor((strtotime($date1)-strtotime($date2))%86400%60);\necho \"\u76f8\u5dee\u79d2\u6570\uff1a\".$second.\"\u79d2\";\n \n\/\/\u8f93\u51fa\uff1a\n\/\/\u76f8\u5dee\u5929\u6570\uff1a0\u5929\n\/\/\u76f8\u5dee\u5c0f\u65f6\u6570\uff1a0\u5c0f\u65f6\n\/\/\u76f8\u5dee\u5206\u949f\u6570\uff1a0\u5206\u949f\n\/\/\u76f8\u5dee\u79d2\u6570\uff1a1\u79d2<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\/** * \u6c42\u4e24\u4e2a\u65e5\u671f\u4e4b\u95f4\u76f8\u5dee\u7684\u5929\u6570 * (\u9488\u5bf91970\u5e741&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-796","post","type-post","status-publish","format-standard","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/posts\/796","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/comments?post=796"}],"version-history":[{"count":1,"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/posts\/796\/revisions"}],"predecessor-version":[{"id":1126,"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/posts\/796\/revisions\/1126"}],"wp:attachment":[{"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/media?parent=796"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/categories?post=796"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/tags?post=796"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}