{"id":77,"date":"2012-11-27T11:44:32","date_gmt":"2012-11-27T03:44:32","guid":{"rendered":"http:\/\/www.yeetrack.com\/post\/2012-11-27\/php%25E6%2597%25B6%25E9%2597%25B4%25E5%25A4%2584%25E7%2590%2586%25E5%2587%25BD%25E6%2595%25B0"},"modified":"2013-04-20T17:25:00","modified_gmt":"2013-04-20T09:25:00","slug":"php%e6%97%b6%e9%97%b4%e5%a4%84%e7%90%86%e5%87%bd%e6%95%b0","status":"publish","type":"post","link":"https:\/\/www.yeetrack.com\/?p=77","title":{"rendered":"php\u65f6\u95f4\u5904\u7406\u51fd\u6570"},"content":{"rendered":"<p>\u7a0b\u5e8f\u4e2d\u4e00\u822c\u4f7f\u7528Unix\u65f6\u95f4\u6233\u6765\u8ba1\u7b97\u548c\u4fdd\u7559\u65f6\u95f4\uff0cphp\u4e2d\u7528\u6765\u5904\u7406\u65f6\u95f4\u7684\u51fd\u6570\u6709mktime()\u5c06\u65f6\u95f4\u8f6c\u4e3aUnix\u65f6\u95f4<\/p>\n<p><!--more--><\/p>\n<p>\uff1bstrtotime()\u5c06\u82f1\u6587\u81ea\u7136\u65f6\u95f4\u8f6c\u4e3aUnix\u65f6\u95f4\uff1bgetdate()\u5c06Unix\u65f6\u95f4\u8f6c\u4e3a\u5173\u8054\u6570\u7ec4\uff1bdate_default_timezone_set()\u8bbe\u7f6e\u65f6\u533a\uff1bmicrotime()\u8fd4\u56de\u5fae\u79d2\u65f6\u95f4\uff0c\u8be6\u7ec6\u5982\u4e0b\u9762\u4ee3\u7801\uff1a<\/p>\n<pre config=\"brush:php;toolbar:false;\">&lt;?php\n    \/\/\u5c06\u65f6\u533a\u8bbe\u4e3a\u5317\u4eac\u65f6\u95f4\uff0c\u5426\u5219\u9ed8\u8ba4\u4e3a\u683c\u6797\u5a01\u6cbb\u65f6\u95f4(\u5728php.ini\u4e2d\u53ef\u4ee5\u4fee\u6539)\uff0c\u4e0e\u5317\u4eac\u65f6\u95f4\u76f8\u5dee8\u5c0f\u65f6\n    date_default_timezone_set(&quot;PRC&quot;);\/\/RPC\u4e3a\u4e2d\u56fd\u82f1\u6587\u7b80\u79f0\n      \n    \/\/mktime()\u7528\u4e8e\u5c06\u65e5\u671f\u548c\u65f6\u95f4\u8f6c\u5316\u4e3aUnix\u65f6\u95f4\u6233,\u540e\u9762\u7684\u53c2\u6570\u4f9d\u6b21\u662f\u5c0f\u65f6\u3001\u5206\u949f\u3001\u79d2\u3001\u6708\u3001\u65e5\u3001\u5e74\uff1b\u7559\u7a7a\u5219\u4f1a\u9ed8\u8ba4\u53bb\u5f53\u524d\u65e5\u671f\n    echo date(&quot;Y-m-d h:i:s&quot;, mktime(1, 2, 3, 4, 5, 2012)) . &quot;&lt;br \/&gt;&quot;;\n    echo mktime(1, 2, 3, 4, 5, 2012) . &quot;&lt;br \/&gt;&quot;;\n      \n    \/\/strtotime()\u53ef\u4ee5\u5c06\u82f1\u8bed\u81ea\u7136\u8bed\u8a00\u63cf\u8ff0\u7684\u65e5\u671f\u8f6c\u6362\u6210\u65f6\u95f4\u6233\n    echo strtotime(&quot;now&quot;) . &quot;&lt;br \/&gt;&quot;;\n    echo date(&quot;Y-m-d h:i:s&quot;, strtotime(&quot;now&quot;)) . &quot;&lt;br\/&gt;&quot;;\n    echo date(&quot;Y-m-d h:i:s&quot;, strtotime(&quot;yesterday&quot;)) . &quot;&lt;br\/&gt;&quot;;\n    echo date(&quot;Y-m-d h:i:s&quot;, strtotime(&quot;last sunday&quot;)) .&quot;&lt;br \/&gt;&quot;;\n      \n    \/\/\u7528Unix\u65f6\u95f4\u6233\u6765\u8ba1\u7b97\u65f6\u95f4\u5dee\n    $year = 1990;\n    $month = 1;\n    $day = 1;\n    $birthday = mktime(0, 0, 0, $month, $day, $year);\n    $now = time();\n    $ageUnix = $now - $birthday;\n    $age = floor($ageUnix \/ (365*24*60*60));\n    echo &quot;You are &quot; . $age . &quot; years old!&quot; . &quot;&lt;br \/&gt;&quot;;\n      \n    \/\/getdate()\u51fd\u6570\u8fd4\u56de\u4e00\u4e2a\u7531\u65f6\u95f4\u6233\u7ec4\u6210\u7684\u5173\u8054\u6570\u7ec4\uff0c\u53c2\u6570\u662f\u4e00\u4e2a\u53ef\u9009\u7684unix\u65f6\u95f4\u6233\uff0c\u5982\u679c\u4e3a\u7a7a\uff0c\u5c31\u53d6\u5f53\u524d\u7cfb\u7edf\u65f6\u95f4\n    $time = mktime(1, 2, 3 , 4, 5, 2012);\n    $myDate = getdate($time);\n    print_r($myDate);\n    echo &quot;&lt;br \/&gt;&quot;;\n    echo &quot;$myDate[weekday], $myDate[month] $myDate[mday], $myDate[year]&quot; . &quot;&lt;br \/&gt;&quot;;\n      \n    \/\/Unix\u65f6\u95f4\u6233\u6700\u5c0f\u5355\u4f4d\u4e3a\u79d2\uff0c\u5982\u679c\u60f3\u7cbe\u786e\u5230\u6beb\u79d2\u7ea7\uff0c\u53ef\u4ee5\u4f7f\u7528microtime()\u51fd\u6570\uff0c\u8be5\u51fd\u6570\u8fd4\u56deUnix\u65f6\u95f4\u6233\u548c\u5fae\u79d2\u6570\n    $startTime = microtime(true);\n    echo &quot;Start time : &quot; . $startTime . &quot;&lt;br \/&gt;&quot;;\n    $stopTime = microtime(true);\n    echo &quot;Stop time : &quot; . $stopTime . &quot;&lt;br \/&gt;&quot;; \n    echo &quot;time used : &quot; . ($stopTime-$startTime) . &quot;seconds&lt;br\/&gt;&quot;;\n      \n?&gt;<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u7a0b\u5e8f\u4e2d\u4e00\u822c\u4f7f\u7528Unix\u65f6\u95f4\u6233\u6765\u8ba1\u7b97\u548c\u4fdd\u7559\u65f6\u95f4\uff0cphp\u4e2d\u7528\u6765\u5904\u7406\u65f6\u95f4\u7684\u51fd\u6570\u6709mktime()\u5c06\u65f6\u95f4\u8f6c\u4e3aUnix\u65f6\u95f4<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"pgc_sgb_lightbox_settings":"","footnotes":""},"categories":[33],"tags":[24,7],"class_list":["post-77","post","type-post","status-publish","format-standard","hentry","category-coding","tag-php","tag-7"],"views":2738,"_links":{"self":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts\/77","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=77"}],"version-history":[{"count":2,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts\/77\/revisions"}],"predecessor-version":[{"id":387,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts\/77\/revisions\/387"}],"wp:attachment":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=77"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=77"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=77"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}