{"id":23202,"date":"2024-11-21T08:37:51","date_gmt":"2024-11-21T00:37:51","guid":{"rendered":"https:\/\/fwq.ai\/blog\/23202\/"},"modified":"2024-11-21T08:37:51","modified_gmt":"2024-11-21T00:37:51","slug":"thinkphp5-1%e4%b8%ad%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8%e6%97%b6%e9%97%b4%e5%a4%84%e7%90%86%e5%87%bd%e6%95%b0","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/23202\/","title":{"rendered":"ThinkPHP5.1\u4e2d\u5982\u4f55\u4f7f\u7528\u65f6\u95f4\u5904\u7406\u51fd\u6570"},"content":{"rendered":"<\/p>\n<p><strong>\u4e00\u3001\u65f6\u95f4\u6233\u8f6c\u6362\u4e3a\u65e5\u671f\u65f6\u95f4<\/strong><\/p>\n<p>\u5728 PHP \u4e2d\uff0cUNIX \u65f6\u95f4\u6233\u53ef\u4ee5\u88ab\u8f6c\u5316\u4e3a\u65e5\u671f\u65f6\u95f4\u5b57\u7b26\u4e32\uff0c\u8fd9\u662f\u901a\u8fc7\u8c03\u7528 date() \u51fd\u6570\u5b9e\u73b0\u7684\u3002\u5728 ThinkPHP5.1 \u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 hinkhelperStr \u7c7b\u7684 toDateTimeString() \u65b9\u6cd5\u6765\u5c06\u65f6\u95f4\u6233\u8f6c\u6362\u4e3a\u65e5\u671f\u65f6\u95f4\u5b57\u7b26\u4e32\u3002<\/p>\n<p>\u4f8b\u5982\uff1a<\/p>\n<pre>use&nbsp;thinkhelperStr;\n\n$time&nbsp;=&nbsp;1573679399;\necho&nbsp;Str::toDateTimeString($time);\n\/\/&nbsp;\u8f93\u51fa:&nbsp;2019-11-14&nbsp;14:03:19<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4e8c\u3001\u65e5\u671f\u65f6\u95f4\u8f6c\u6362\u4e3a\u65f6\u95f4\u6233<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p>\u5728 PHP \u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 strtotime() \u51fd\u6570\u5c06\u65e5\u671f\u65f6\u95f4\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a UNIX \u65f6\u95f4\u6233\u3002\u5728 ThinkPHP5.1 \u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 hinkhelperStr \u7c7b\u7684 unixTime() \u65b9\u6cd5\u6765\u5c06\u65e5\u671f\u65f6\u95f4\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u65f6\u95f4\u6233\u3002<\/p>\n<p>\u4f8b\u5982\uff1a<\/p>\n<pre>use&nbsp;thinkhelperStr;\n\n$datetime&nbsp;=&nbsp;'2019-11-14&nbsp;14:03:19';\necho&nbsp;Str::unixTime($datetime);\n\/\/&nbsp;\u8f93\u51fa:&nbsp;1573679399<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4e09\u3001\u65f6\u95f4\u683c\u5f0f\u5316<\/strong><\/p>\n<p>\u5728 PHP \u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 date() \u51fd\u6570\u5bf9\u65e5\u671f\u65f6\u95f4\u5b57\u7b26\u4e32\u8fdb\u884c\u683c\u5f0f\u5316\u3002\u5728 ThinkPHP5.1 \u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 hinkhelperStr \u7c7b\u7684 dateFormat() \u65b9\u6cd5\u5bf9\u65e5\u671f\u65f6\u95f4\u5b57\u7b26\u4e32\u8fdb\u884c\u683c\u5f0f\u5316\u3002<\/p>\n<p>\u4f8b\u5982\uff1a<\/p>\n<pre>use&nbsp;thinkhelperStr;\n\n$datetime&nbsp;=&nbsp;'2019-11-14&nbsp;14:03:19';\necho&nbsp;Str::dateFormat($datetime,&nbsp;'Y\u5e74m\u6708d\u65e5&nbsp;H:i:s');\n\/\/&nbsp;\u8f93\u51fa:&nbsp;2019\u5e7411\u670814\u65e5&nbsp;14:03:19<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728 dateFormat() \u65b9\u6cd5\u4e2d\uff0c\u7b2c\u4e00\u4e2a\u53c2\u6570\u662f\u9700\u8981\u683c\u5f0f\u5316\u7684\u65e5\u671f\u65f6\u95f4\u5b57\u7b26\u4e32\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u662f\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u3002\u5e38\u7528\u7684\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u5982\u4e0b\uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th>\u65e5\u671f\u683c\u5f0f\u5b57\u7b26<\/th>\n<th>\u8bf4\u660e<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Y<\/td>\n<td>\u5e74\u4efd\uff084 \u4f4d\u6570\uff09<\/td>\n<\/tr>\n<tr>\n<td>m<\/td>\n<td>\u6708\u4efd\uff0801-12\uff09<\/td>\n<\/tr>\n<tr>\n<td>d<\/td>\n<td>\u65e5\u671f\uff0801-31\uff09<\/td>\n<\/tr>\n<tr>\n<td>H<\/td>\n<td>\u5c0f\u65f6\uff0800-23\uff09<\/td>\n<\/tr>\n<tr>\n<td>i<\/td>\n<td>\u5206\u949f\uff0800-59\uff09<\/td>\n<\/tr>\n<tr>\n<td>s<\/td>\n<td>\u79d2\u949f\uff0800-59\uff09<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>\u56db\u3001\u65f6\u95f4\u5dee\u8ba1\u7b97<\/strong><\/p>\n<p>\u5728 PHP \u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 strtotime() \u51fd\u6570\u8ba1\u7b97\u4e24\u4e2a\u65e5\u671f\u65f6\u95f4\u4e4b\u95f4\u7684\u65f6\u95f4\u5dee\u3002\u5728 ThinkPHP5.1 \u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 hinkhelperStr \u7c7b\u7684 time() \u65b9\u6cd5\u8ba1\u7b97\u4e24\u4e2a\u65e5\u671f\u65f6\u95f4\u4e4b\u95f4\u7684\u65f6\u95f4\u5dee\u3002<\/p>\n<p>\u4f8b\u5982\uff1a<\/p>\n<pre>use&nbsp;thinkhelperStr;\n\n$start&nbsp;=&nbsp;'2019-11-14&nbsp;14:03:19';\n$end&nbsp;=&nbsp;'2019-11-15&nbsp;16:05:12';\n\n$diff&nbsp;=&nbsp;Str::time($start,&nbsp;$end);\n\necho&nbsp;$diff-&amp;gt;format('%a&nbsp;\u5929&nbsp;%h&nbsp;\u5c0f\u65f6&nbsp;%i&nbsp;\u5206\u949f&nbsp;%s&nbsp;\u79d2');\n\/\/&nbsp;\u8f93\u51fa:&nbsp;1&nbsp;\u5929&nbsp;2&nbsp;\u5c0f\u65f6&nbsp;1&nbsp;\u5206\u949f&nbsp;53&nbsp;\u79d2<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728 time() \u65b9\u6cd5\u4e2d\uff0c\u7b2c\u4e00\u4e2a\u53c2\u6570\u662f\u5f00\u59cb\u65f6\u95f4\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u662f\u7ed3\u675f\u65f6\u95f4\u3002\u5982\u679c\u8981\u8ba1\u7b97\u4e24\u4e2a\u65f6\u95f4\u4e4b\u95f4\u7684\u5929\u6570\u3001\u5c0f\u65f6\u6570\u3001\u5206\u949f\u6570\u3001\u79d2\u6570\u7b49\u7b49\uff0c\u53ef\u4ee5\u4f7f\u7528 DateTime \u5bf9\u8c61\u7684 format() \u65b9\u6cd5\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fThinkPHP5.1\u4e2d\u5982\u4f55\u4f7f\u7528\u65f6\u95f4\u5904\u7406\u51fd\u6570\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u65f6\u95f4\u6233\u8f6c\u6362\u4e3a\u65e5\u671f\u65f6\u95f4 \u5728 PHP \u4e2d\uff0cUNIX \u65f6\u95f4\u6233\u53ef\u4ee5\u88ab\u8f6c\u5316\u4e3a\u65e5\u671f\u65f6\u95f4\u5b57\u7b26\u4e32\uff0c\u8fd9\u662f\u901a\u8fc7\u8c03\u7528 date() \u51fd\u6570\u5b9e\u73b0\u7684\u3002\u5728 ThinkPHP5.1 \u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 hinkhelperStr \u7c7b\u7684 toDateTimeString() \u65b9\u6cd5\u6765\u5c06\u65f6\u95f4\u6233\u8f6c\u6362\u4e3a\u65e5\u671f\u65f6\u95f4\u5b57\u7b26\u4e32\u3002 \u4f8b\u5982\uff1a use&nbsp;thinkhelperStr; $time&nbsp;=&nbsp;1573679399; echo&nbsp;Str::toDateTimeString($time); \/\/&nbsp;\u8f93\u51fa:&nbsp;2019-11-14&nbsp;14:03:19 \u767b\u5f55\u540e\u590d\u5236 \u4e8c\u3001\u65e5\u671f\u65f6\u95f4\u8f6c\u6362\u4e3a\u65f6\u95f4\u6233 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u5728 PHP \u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 strtotime() \u51fd\u6570\u5c06\u65e5\u671f\u65f6\u95f4\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a UNIX \u65f6\u95f4\u6233\u3002\u5728 ThinkPHP5.1 \u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 hinkhelperStr \u7c7b\u7684 unixTime() \u65b9\u6cd5\u6765\u5c06\u65e5\u671f\u65f6\u95f4\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u65f6\u95f4\u6233\u3002 \u4f8b\u5982\uff1a use&nbsp;thinkhelperStr; $datetime&nbsp;=&nbsp;&#8216;2019-11-14&nbsp;14:03:19&#8217;; echo&nbsp;Str::unixTime($datetime); \/\/&nbsp;\u8f93\u51fa:&nbsp;1573679399 \u767b\u5f55\u540e\u590d\u5236 \u4e09\u3001\u65f6\u95f4\u683c\u5f0f\u5316 \u5728 PHP \u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 date() \u51fd\u6570\u5bf9\u65e5\u671f\u65f6\u95f4\u5b57\u7b26\u4e32\u8fdb\u884c\u683c\u5f0f\u5316\u3002\u5728 ThinkPHP5.1 \u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 hinkhelperStr \u7c7b\u7684 dateFormat() \u65b9\u6cd5\u5bf9\u65e5\u671f\u65f6\u95f4\u5b57\u7b26\u4e32\u8fdb\u884c\u683c\u5f0f\u5316\u3002 \u4f8b\u5982\uff1a use&nbsp;thinkhelperStr; $datetime&nbsp;=&nbsp;&#8216;2019-11-14&nbsp;14:03:19&#8217;; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-23202","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/23202","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=23202"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/23202\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=23202"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=23202"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=23202"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}