{"id":952,"date":"2023-09-03T17:41:29","date_gmt":"2023-09-03T08:41:29","guid":{"rendered":"https:\/\/shinke1987.net\/?p=952"},"modified":"2023-09-17T15:23:41","modified_gmt":"2023-09-17T06:23:41","slug":"carbonimmutable%e9%96%a2%e9%80%a3%e5%80%8b%e4%ba%ba%e7%9a%84%e3%81%be%e3%81%a8%e3%82%81","status":"publish","type":"post","link":"https:\/\/shinke1987.net\/?p=952","title":{"rendered":"CarbonImmutable\u95a2\u9023\u500b\u4eba\u7684\u307e\u3068\u3081"},"content":{"rendered":"\n<h2 id=\"toc0\" class=\"wp-block-heading\">\u6982\u8981<\/h2>\n\n\n\n<p><a href=\"https:\/\/carbon.nesbot.com\" target=\"_blank\" rel=\"noreferrer noopener\">\u516c\u5f0f\u30b5\u30a4\u30c8<\/a>\u306b\u30ea\u30d5\u30a1\u30ec\u30f3\u30b9\u304c\u3042\u308b\u306e\u3067\u8aad\u3080\u3068\u826f\u3044\u3002<br>Laravel\u306eTinker\u3092\u5229\u7528\u3057\u3066\u78ba\u8a8d\u3059\u308b\u3068\u826f\u3044\u3002<br>(use Carbon\\CarbonImmutable; \u3092\u5fd8\u308c\u305a\u306b)<\/p>\n\n\n\n<h2 id=\"toc1\" class=\"wp-block-heading\">\u73fe\u5728\u306e\u65e5\u6642\u3068\u66dc\u65e5\u3092\u53d6\u5f97<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n$now = CarbonImmutable::now();\n\n$now = new CarbonImmutable();\n\n\/\/ \u66dc\u65e5\n$now-&gt;dayOfWeek;\n\n$now-&gt;isDayOfWeek(Carbon::SUNDAY);\n<\/pre><\/div>\n\n\n<h2 id=\"toc2\" class=\"wp-block-heading\">\u6307\u5b9a\u3057\u305f\u6642\u9593\u7d4c\u904e\u5f8c\u306e\u65e5\u6642\u3092\u53d6\u5f97<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n$tommorow = CarbonImmutable::now()-&gt;add(1, &#039;day&#039;);\n\n$now = new CarbonImmutable();\n$tommorow = $now-&gt;add(1, &#039;day&#039;);\n$someDay = $now-&gt;add(-90, &#039;day&#039;);\n$someWeek = $now-&gt;add(2, &#039;week&#039;);\n$someMonth = $now-&gt;add(2, &#039;month&#039;);\n$someYear = $now-&gt;add(2, &#039;year&#039;);\n<\/pre><\/div>\n\n\n<h2 id=\"toc3\" class=\"wp-block-heading\">\u6642\u5206\u79d2\u306e\u5024\u3092\u8a2d\u5b9a<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n$now = new CarbonImmutable();\n\n$now-&gt;hours(0);\n$now-&gt;minutes(0);\n$now-&gt;seconds(0);\n$now-&gt;milliseconds(0);\n$now-&gt;microseconds(0);\n\n$past = $now-&gt;add(-90, &#039;day&#039;);\n$past = $past-&gt;hours(0)-&gt;minutes(0)-&gt;seconds(0)-&gt;microseconds(0);\n<\/pre><\/div>\n\n\n<h2 id=\"toc4\" class=\"wp-block-heading\">\u65e5\u6642\u306e\u5dee\u3092\u53d6\u5f97<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n$now = new CarbonImmutable();\n\n$someDay = $now-&gt;add(-90, &#039;day&#039;);\n$someWeek = $now-&gt;add(2, &#039;week&#039;);\n$someMonth = $now-&gt;add(2, &#039;month&#039;);\n$someYear = $now-&gt;add(2, &#039;year&#039;);\n\n$resultDiff = $now-&gt;diff($someDay);\n\n$resultDiffDays = $now-&gt;diffInDays($someDay);\n\n$resultDiffWeeks = $now-&gt;diffInWeeks($someWeek);\n\n$resultDiffMonths = $now-&gt;diffInMonths($someMonth);\n\n$resultDiffYears = $now-&gt;diffInYears($someYear);\n<\/pre><\/div>\n\n\n<h2 id=\"toc5\" class=\"wp-block-heading\">\u65e5\u6642\u3092\u6bd4\u8f03<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n$now1 = $now2 = new CarbonImmutable();\n\n$tommorow = $now1-&gt;add(1, &#039;week&#039;);\n\n$now1-&gt;equalTo($now2);\n$now1-&gt;notEqualTo($tommorow);\n$now1-&gt;greaterThan($now2);\n$now1-&gt;greaterThanOrEqualTo($now2);\n$now1-&gt;lessThan($now2);\n$now1-&gt;lessThanOrEqualTo($now2);\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>\u6982\u8981 \u516c\u5f0f\u30b5\u30a4\u30c8\u306b\u30ea\u30d5\u30a1\u30ec\u30f3\u30b9\u304c\u3042\u308b\u306e\u3067\u8aad\u3080\u3068\u826f\u3044\u3002Laravel\u306eTinker\u3092\u5229\u7528\u3057\u3066\u78ba\u8a8d\u3059\u308b\u3068\u826f\u3044\u3002(use Carbon\\CarbonImmutable; \u3092\u5fd8\u308c\u305a\u306b) \u73fe\u5728\u306e\u65e5\u6642\u3068\u66dc\u65e5\u3092\u53d6\u5f97 \u6307\u5b9a\u3057\u305f\u6642\u9593\u7d4c\u904e\u5f8c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[96],"tags":[88,81],"class_list":["post-952","post","type-post","status-publish","format-standard","hentry","category-laravel","tag-laravel","tag-php"],"_links":{"self":[{"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/posts\/952","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/shinke1987.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=952"}],"version-history":[{"count":2,"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/posts\/952\/revisions"}],"predecessor-version":[{"id":954,"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/posts\/952\/revisions\/954"}],"wp:attachment":[{"href":"https:\/\/shinke1987.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=952"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/shinke1987.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=952"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/shinke1987.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=952"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}