Lấy php năm hiện tại

One important thing you should remember is that the timestamp value returned by time[] is time-zone agnostic and gets the number of seconds since 1 January 1970 at 00:00:00 UTC. This means that at a particular point in time, this function will return the same value in the US, Europe, India, Japan, ...

date[] will format a time-zone agnostic timestamp according to the default timezone set with date_default_timezone_set[...]. Local time. If you want to output as UTC time use:

function dateUTC[$format, $timestamp = null]
{
    if [$timestamp === null] $timestamp = time[];

    $tz = date_default_timezone_get[];
    date_default_timezone_set['UTC'];

    $result = date[$format, $timestamp];

    date_default_timezone_set[$tz];
    return $result;
}
/>

If you really love your fluid method calls and get frustrated by the extra line or ugly pair of brackets necessary when using the constructor you'll enjoy the

use Carbon\Carbon;
69 method

echo [new Carbon['first day of December 2008']]->addWeeks[2];     // 2008-12-15 00:00:00
echo "\n";
echo Carbon::parse['first day of December 2008']->addWeeks[2];    // 2008-12-15 00:00:00

The string passed to

use Carbon\Carbon;
70 or to
use Carbon\Carbon;
71 can represent a relative time [next sunday, tomorrow, first day of next month, last year] or an absolute time [first day of December 2008, 2017-01-06]. You can test if a string will produce a relative or absolute date with
use Carbon\Carbon;
72

$string = 'first day of next month';
if [strtotime[$string] === false] {
    echo "'$string' is not a valid date/time string.";
} elseif [Carbon::hasRelativeKeywords[$string]] {
    echo "'$string' is a relative valid date/time string, it will returns different dates depending on the current date.";
} else {
    echo "'$string' is an absolute date/time string, it will always returns the same date.";
}

To accompany

use Carbon\Carbon;
68, a few other static instantiation helpers exist to create widely known instances. The only thing to really notice here is that
use Carbon\Carbon;
74,
use Carbon\Carbon;
75 and
use Carbon\Carbon;
76, besides behaving as expected, all accept a timezone parameter and each has their time value set to
use Carbon\Carbon;
77

$now = Carbon::now[];
echo $now;                               // 2022-12-31 15:56:18
echo "\n";
$today = Carbon::today[];
echo $today;                             // 2022-12-31 00:00:00
echo "\n";
$tomorrow = Carbon::tomorrow['Europe/London'];
echo $tomorrow;                          // 2023-01-01 00:00:00
echo "\n";
$yesterday = Carbon::yesterday[];
echo $yesterday;                         // 2022-12-30 00:00:00

The next group of static helpers are the

use Carbon\Carbon;
78 helpers. Most of the static
use Carbon\Carbon;
79 functions allow you to provide as many or as few arguments as you want and will provide default values for all others. Generally default values are the current date, time or timezone. Higher values will wrap appropriately but invalid values will throw an
use Carbon\Carbon;
80 with an informative message. The message is obtained from an DateTime. getLastErrors[] call

$year = 2000; $month = 4; $day = 19;
$hour = 20; $minute = 30; $second = 15; $tz = 'Europe/Madrid';
echo Carbon::createFromDate[$year, $month, $day, $tz]."\n";
echo Carbon::createMidnightDate[$year, $month, $day, $tz]."\n";
echo Carbon::createFromTime[$hour, $minute, $second, $tz]."\n";
echo Carbon::createFromTimeString["$hour:$minute:$second", $tz]."\n";
echo Carbon::create[$year, $month, $day, $hour, $minute, $second, $tz]."\n";

use Carbon\Carbon;
81 will default the time to now.
use Carbon\Carbon;
82 will default the date to today.
use Carbon\Carbon;
83 will default any null parameter to the current respective value. As before, the
use Carbon\Carbon;
84 defaults to the current timezone and otherwise can be a DateTimeZone instance or simply a string timezone value. The only special case is for
use Carbon\Carbon;
83 that has minimum value as default for missing argument but default on current value when you pass explicitly
use Carbon\Carbon;
86

use Carbon\Carbon;
0

Create exceptions occurs on such negative values but not on overflow, to get exceptions on overflow, use

use Carbon\Carbon;
87

use Carbon\Carbon;
1

Note 1. 2018-02-29 also throws an exception while 2020-02-29 does not since 2020 is a leap year

Note 2.

use Carbon\Carbon;
88 also produces an exception as this time is in an hour skipped by the daylight saving time

Note 3. The PHP native API allow consider there is a year

use Carbon\Carbon;
89 between
use Carbon\Carbon;
90 and
use Carbon\Carbon;
91 even if it doesn't regarding to Gregorian calendar. That's why years lower than 1 will throw an exception using
use Carbon\Carbon;
92. Check for year-0 detection

use Carbon\Carbon;
2

use Carbon\Carbon;
93 is mostly a wrapper for the base php function DateTime. createFromFormat. The difference being again the
use Carbon\Carbon;
84 argument can be a DateTimeZone instance or a string timezone value. Also, if there are errors with the format this function will call the
use Carbon\Carbon;
95 method and then throw a
use Carbon\Carbon;
80 with the errors as the message

use Carbon\Carbon;
3

You can test if a date matches a format for

use Carbon\Carbon;
93 [e. g. date/time components, modifiers or separators] using
use Carbon\Carbon;
98 or
use Carbon\Carbon;
99 which also ensure data is actually enough to create an instance

use Carbon\Carbon;
4

You can create instances from unix timestamps.

$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
00 create a Carbon instance equal to the given timestamp and will set the timezone as well or default it to the current timezone.
$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
01, is different in that the timezone will remain UTC [GMT+00. 00], it's equivalent to
$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
02 but it supports int, float or string containing one or more numbers [like the one produced by
$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
03] so it can also set microseconds with no precision lost. The third,
$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
04, accepts a timestamp in milliseconds instead of seconds. Negative timestamps are also allowed

use Carbon\Carbon;
5

You can also create a

$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
05 of an existing Carbon instance. As expected the date, time and timezone values are all copied to the new instance

use Carbon\Carbon;
6

You can use

$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
06 on an existing Carbon instance to get a new instance at now in the same timezone

use Carbon\Carbon;
7

Cuối cùng, nếu bạn thấy mình kế thừa một phiên bản

$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
07 từ một thư viện khác, đừng lo. Bạn có thể tạo một phiên bản
$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
08 thông qua một phương pháp thân thiện với
$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
09. Hoặc sử dụng phương pháp thậm chí linh hoạt hơn
$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
10 có thể trả về một phiên bản Carbon mới từ DateTime, Carbon hoặc từ một chuỗi, nếu không, nó chỉ trả về null

use Carbon\Carbon;
8

Carbon 2 [yêu cầu PHP >= 7. 1] hỗ trợ hoàn hảo micro giây. Nhưng nếu bạn sử dụng Carbon 1 và PHP add[1, 'day']; $modifiedImmutable = CarbonImmutable::now[]->add[1, 'day']; var_dump[$modifiedMutable === $mutable]; // bool[true] var_dump[$mutable->isoFormat['dddd D']]; // string[8] "Sunday 1" var_dump[$modifiedMutable->isoFormat['dddd D']]; // string[8] "Sunday 1" // So it means $mutable and $modifiedMutable are the same object // both set to now + 1 day. var_dump[$modifiedImmutable === $immutable]; // bool[false] var_dump[$immutable->isoFormat['dddd D']]; // string[11] "Saturday 31" var_dump[$modifiedImmutable->isoFormat['dddd D']]; // string[8] "Sunday 1" // While $immutable is still set to now and cannot be changed and // $modifiedImmutable is a new instance created from $immutable // set to now + 1 day. $mutable = CarbonImmutable::now[]->toMutable[]; var_dump[$mutable->isMutable[]]; // bool[true] var_dump[$mutable->isImmutable[]]; // bool[false] $immutable = Carbon::now[]->toImmutable[]; var_dump[$immutable->isMutable[]]; // bool[false] var_dump[$immutable->isImmutable[]]; // bool[true] 11 và không thể thay đổi sau đó, điều này có nghĩa là

use Carbon\Carbon;
9

To work around this limitation in Carbon, we append microseconds when calling

$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
12 in PHP < 7. 1, but this feature can be disabled on demand [no effect in PHP >= 7. 1]

$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
0

Ever need to loop through some dates to find the earliest or latest date? Didn't know what to set your initial maximum/minimum values to? There are now two helpers for this to make your decision simple

$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
1

Min and max value mainly depends on the system [32 or 64 bit]

With a 32-bit OS system or 32-bit version of PHP [you can check it in PHP with

$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
13], the minimum value is the 0-unix-timestamp [1970-01-01 00. 00. 00] and the maximum is the timestamp given by the constant
$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
14

With a 64-bit OS system and 64-bit version of PHP, the minimum is 01-01-01 00. 00. 00 and maximum is 9999-12-31 23. 59. 59. It's even possible to use negative year up to -9999 but be aware you may not have accurate results with some operations as the year 0 exists in PHP but not in the Gregorian calendar

With Carbon 2, localization changed a lot, 750 new locales are supported and we now embed locale formats, day names, month names, ordinal suffixes, meridiem, week start and more. While Carbon 1 provided partial support and relied on third-party like IntlDateFormatter class and language packages for advanced translation, you now benefit of a wide internationalization support. You still use Carbon 1? I hope you would consider to upgrade, version 2 has really cool new features. Otherwise you can find the

Unfortunately the base class DateTime does not have any localization support. To begin localization support a

$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
15 method was added. The implementation makes a call to strftime using the current instance timestamp. If you first set the current locale with PHP function setlocale[] then the string returned will be formatted in the correct locale

$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
2

$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
16 has also been localized. You can set the Carbon locale by using the static
$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
17 function and get the current setting with
$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
18

$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
3

Or you can isolate some code with a given locale

$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
4

Some languages require utf8 encoding to be printed [locale packages that does not ends with

$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
19 mainly]. In this case you can use the static method
$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
20 to encode the result of the formatLocalized[] call to the utf8 charset

$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
5

on Linux
If you have trouble with translations, check locales installed in your system [local and production]

$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
21 to list locales enabled
$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
22 to install a new locale
$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
23 to publish all locale enabled
And reboot your system

Since 2. 9. 0, you can easily customize translations

$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
6

You can use fallback locales by passing in order multiple ones to

$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
24

$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
7

In the example above, it will try to find translations in "xx" in priority, then in "xy" if missing, then in "es", so here, you get "Xday" from "xx", "Yday" from "xy", and "hace" and "minutos" from "es"

Note that you can also use an other translator with

$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
25 as long as the given translator implements
$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
26. And you can get the global default translator using
$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
27 [and
$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
28 and
$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
29 for the fallback locale, setFallbackLocale can be called multiple times to get multiple fallback locales] but as those method will change the behavior globally [including third-party libraries you may have in your app], it might cause unexpected results. You should rather customize translation using custom locales as in the example above

Carbon embed a default translator that extends Symfony\Component\Translation\Translator You can

So the support of a locale for

$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
30, getters such as
$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
31,
$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
32 and short variants is driven by locales installed in your operating system. For other translations, it's supported internally thanks to Carbon community. You can check what's supported with the following methods

$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
8

So, here is the new recommended way to handle internationalization with Carbon

$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
9

The

$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
33 method only change the language for the current instance and has precedence over global settings. We recommend you this approach so you can't have conflict with other places or third-party libraries that could use Carbon. Nevertheless, to avoid calling
$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
33 each time, you can use factories

$dtToronto = Carbon::create[2012, 1, 1, 0, 0, 0, 'America/Toronto'];
$dtVancouver = Carbon::create[2012, 1, 1, 0, 0, 0, 'America/Vancouver'];
// Try to replace the 4th number [hours] or the last argument [timezone] with
// Europe/Paris for example and see the actual result on the right hand.
// It's alive!

echo $dtVancouver->diffInHours[$dtToronto]; // 3
// Now, try to double-click on "diffInHours" or "create" to open
// the References panel.
// Once the references panel is open, you can use the search field to
// filter the list or click the [add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
35 method which is a way to group in one call settings of locale, timezone, months/year overflow, etc. []

$dtToronto = Carbon::create[2012, 1, 1, 0, 0, 0, 'America/Toronto'];
$dtVancouver = Carbon::create[2012, 1, 1, 0, 0, 0, 'America/Vancouver'];
// Try to replace the 4th number [hours] or the last argument [timezone] with
// Europe/Paris for example and see the actual result on the right hand.
// It's alive!

echo $dtVancouver->diffInHours[$dtToronto]; // 3
// Now, try to double-click on "diffInHours" or "create" to open
// the References panel.
// Once the references panel is open, you can use the search field to
// filter the list or click the [add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
35 also allow to pass local macros

$dtToronto = Carbon::create[2012, 1, 1, 0, 0, 0, 'America/Toronto'];
$dtVancouver = Carbon::create[2012, 1, 1, 0, 0, 0, 'America/Vancouver'];
// Try to replace the 4th number [hours] or the last argument [timezone] with
// Europe/Paris for example and see the actual result on the right hand.
// It's alive!

echo $dtVancouver->diffInHours[$dtToronto]; // 3
// Now, try to double-click on "diffInHours" or "create" to open
// the References panel.
// Once the references panel is open, you can use the search field to
// filter the list or click the [add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
37 or to merge new settings with existing ones
$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
38 and the class to generate can be initialized as the second argument of the construct then changed later with
$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
39

$dtToronto = Carbon::create[2012, 1, 1, 0, 0, 0, 'America/Toronto'];
$dtVancouver = Carbon::create[2012, 1, 1, 0, 0, 0, 'America/Vancouver'];
// Try to replace the 4th number [hours] or the last argument [timezone] with
// Europe/Paris for example and see the actual result on the right hand.
// It's alive!

echo $dtVancouver->diffInHours[$dtToronto]; // 3
// Now, try to double-click on "diffInHours" or "create" to open
// the References panel.
// Once the references panel is open, you can use the search field to
// filter the list or click the [add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
40 that set globally the locale. But as for our other static setters, we highly discourage you to use it. It breaks the principle of isolation because the configuration will apply for every class that uses Carbon

You also may know

$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
41 method from Carbon 1. This method still works the same in Carbon 2 but you should better use
$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
42 instead

$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
43 use ISO format rather than PHP-specific format and use inner translations rather than language packages you need to install on every machine where you deploy your application.
$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
44 method is compatible with momentjs format method, it means you can use same format strings as you may have used in moment from front-end or node. js. Here are some examples

$dtToronto = Carbon::create[2012, 1, 1, 0, 0, 0, 'America/Toronto'];
$dtVancouver = Carbon::create[2012, 1, 1, 0, 0, 0, 'America/Vancouver'];
// Try to replace the 4th number [hours] or the last argument [timezone] with
// Europe/Paris for example and see the actual result on the right hand.
// It's alive!

echo $dtVancouver->diffInHours[$dtToronto]; // 3
// Now, try to double-click on "diffInHours" or "create" to open
// the References panel.
// Once the references panel is open, you can use the search field to
// filter the list or click the [diffInHours[$dtToronto]; // 3
// Now, try to double-click on "diffInHours" or "create" to open
// the References panel.
// Once the references panel is open, you can use the search field to
// filter the list or click the [add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
46]

MãVí dụMô tảOD5Số ngày với các số thay thế, chẳng hạn như 三 cho 3 nếu ngôn ngữ là ja_JPOM1Số tháng với các số thay thế, chẳng hạn như ၀၂ cho 2 nếu ngôn ngữ là my_MMOY2017Số năm với các số thay thế, chẳng hạn như ۱۹۹۸ cho 1998 nếu ngôn ngữ là faOH1724, số giờ với các số thay thế, chẳng hạn như ႑႓ cho . 00Time zone offset HH. mmZZ+0000Time zone offset HHmm

Some macro-formats are also available. Here are examples of each in some languages

Codeenfrjahr
$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
48
$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
49
$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
50

$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
51

$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
52

$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
53

$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
54

$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
55

$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
56

$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
57

$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
51
$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
53
$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
55
$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
57

Khi bạn sử dụng định dạng macro với

$mutable = Carbon::now[];
$immutable = CarbonImmutable::now[];
$modifiedMutable = $mutable->add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
62, bạn có thể chỉ định ngôn ngữ để chọn ngôn ngữ mà định dạng macro sẽ được tìm kiếm trong đó

$dtToronto = Carbon::create[2012, 1, 1, 0, 0, 0, 'America/Toronto'];
$dtVancouver = Carbon::create[2012, 1, 1, 0, 0, 0, 'America/Vancouver'];
// Try to replace the 4th number [hours] or the last argument [timezone] with
// Europe/Paris for example and see the actual result on the right hand.
// It's alive!

echo $dtVancouver->diffInHours[$dtToronto]; // 3
// Now, try to double-click on "diffInHours" or "create" to open
// the References panel.
// Once the references panel is open, you can use the search field to
// filter the list or click the [add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
63

$dtToronto = Carbon::create[2012, 1, 1, 0, 0, 0, 'America/Toronto'];
$dtVancouver = Carbon::create[2012, 1, 1, 0, 0, 0, 'America/Vancouver'];
// Try to replace the 4th number [hours] or the last argument [timezone] with
// Europe/Paris for example and see the actual result on the right hand.
// It's alive!

echo $dtVancouver->diffInHours[$dtToronto]; // 3
// Now, try to double-click on "diffInHours" or "create" to open
// the References panel.
// Once the references panel is open, you can use the search field to
// filter the list or click the [diffInHours[$dtToronto]; // 3
// Now, try to double-click on "diffInHours" or "create" to open
// the References panel.
// Once the references panel is open, you can use the search field to
// filter the list or click the [diffInHours[$dtToronto]; // 3
// Now, try to double-click on "diffInHours" or "create" to open
// the References panel.
// Once the references panel is open, you can use the search field to
// filter the list or click the [diffInHours[$dtToronto]; // 3
// Now, try to double-click on "diffInHours" or "create" to open
// the References panel.
// Once the references panel is open, you can use the search field to
// filter the list or click the [addWeeks[2];     // 2008-12-15 00:00:00
echo "\n";
echo Carbon::parse['first day of December 2008']->addWeeks[2];    // 2008-12-15 00:00:00
1

Là một phần của cài đặt

$dtToronto = Carbon::create[2012, 1, 1, 0, 0, 0, 'America/Toronto'];
$dtVancouver = Carbon::create[2012, 1, 1, 0, 0, 0, 'America/Vancouver'];
// Try to replace the 4th number [hours] or the last argument [timezone] with
// Europe/Paris for example and see the actual result on the right hand.
// It's alive!

echo $dtVancouver->diffInHours[$dtToronto]; // 3
// Now, try to double-click on "diffInHours" or "create" to open
// the References panel.
// Once the references panel is open, you can use the search field to
// filter the list or click the [addWeeks[2];     // 2008-12-15 00:00:00
echo "\n";
echo Carbon::parse['first day of December 2008']->addWeeks[2];    // 2008-12-15 00:00:00
2

Ghi chú. Để được hỗ trợ bản địa hóa, hãy xem phần

Sau đây là các hàm bao cho các định dạng phổ biến được cung cấp trong lớp DateTime

echo [new Carbon['first day of December 2008']]->addWeeks[2];     // 2008-12-15 00:00:00
echo "\n";
echo Carbon::parse['first day of December 2008']->addWeeks[2];    // 2008-12-15 00:00:00
3_______1_______4

Bạn có thể sử dụng phương pháp

$dtToronto = Carbon::create[2012, 1, 1, 0, 0, 0, 'America/Toronto'];
$dtVancouver = Carbon::create[2012, 1, 1, 0, 0, 0, 'America/Vancouver'];
// Try to replace the 4th number [hours] or the last argument [timezone] with
// Europe/Paris for example and see the actual result on the right hand.
// It's alive!

echo $dtVancouver->diffInHours[$dtToronto]; // 3
// Now, try to double-click on "diffInHours" or "create" to open
// the References panel.
// Once the references panel is open, you can use the search field to
// filter the list or click the [add[1, 'day'];
$modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];

var_dump[$modifiedMutable === $mutable];             // bool[true]
var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump[$modifiedImmutable === $immutable];         // bool[false]
var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.

$mutable = CarbonImmutable::now[]->toMutable[];
var_dump[$mutable->isMutable[]];                     // bool[true]
var_dump[$mutable->isImmutable[]];                   // bool[false]
$immutable = Carbon::now[]->toImmutable[];
var_dump[$immutable->isMutable[]];                   // bool[false]
var_dump[$immutable->isImmutable[]];                 // bool[true]
08 dựa trên một phiên bản nguồn nhất định được sử dụng làm tài liệu tham khảo khi cần. Nó trả về một thể hiện mới

echo [new Carbon['first day of December 2008']]->addWeeks[2];     // 2008-12-15 00:00:00
echo "\n";
echo Carbon::parse['first day of December 2008']->addWeeks[2];    // 2008-12-15 00:00:00
5

So sánh đơn giản được cung cấp thông qua các chức năng sau. Hãy nhớ rằng việc so sánh được thực hiện theo múi giờ UTC nên mọi thứ không phải lúc nào cũng như vẻ ngoài của chúng

echo [new Carbon['first day of December 2008']]->addWeeks[2];     // 2008-12-15 00:00:00
echo "\n";
echo Carbon::parse['first day of December 2008']->addWeeks[2];    // 2008-12-15 00:00:00
6

Các phương thức đó sử dụng phép so sánh tự nhiên được cung cấp bởi PHP

$dtToronto = Carbon::create[2012, 1, 1, 0, 0, 0, 'America/Toronto'];
$dtVancouver = Carbon::create[2012, 1, 1, 0, 0, 0, 'America/Vancouver'];
// Try to replace the 4th number [hours] or the last argument [timezone] with
// Europe/Paris for example and see the actual result on the right hand.
// It's alive!

echo $dtVancouver->diffInHours[$dtToronto]; // 3
// Now, try to double-click on "diffInHours" or "create" to open
// the References panel.
// Once the references panel is open, you can use the search field to
// filter the list or click the [diffInHours[$dtToronto]; // 3
// Now, try to double-click on "diffInHours" or "create" to open
// the References panel.
// Once the references panel is open, you can use the search field to
// filter the list or click the [diffInHours[$dtToronto]; // 3
// Now, try to double-click on "diffInHours" or "create" to open
// the References panel.
// Once the references panel is open, you can use the search field to
// filter the list or click the [diffInHours[$dtToronto]; // 3
// Now, try to double-click on "diffInHours" or "create" to open
// the References panel.
// Once the references panel is open, you can use the search field to
// filter the list or click the [diffInHours[$dtToronto]; // 3
// Now, try to double-click on "diffInHours" or "create" to open
// the References panel.
// Once the references panel is open, you can use the search field to
// filter the list or click the [diffInHours[$dtToronto]; // 3
// Now, try to double-click on "diffInHours" or "create" to open
// the References panel.
// Once the references panel is open, you can use the search field to
// filter the list or click the [diffInHours[$dtToronto]; // 3
// Now, try to double-click on "diffInHours" or "create" to open
// the References panel.
// Once the references panel is open, you can use the search field to
// filter the list or click the [diffInHours[$dtToronto]; // 3
// Now, try to double-click on "diffInHours" or "create" to open
// the References panel.
// Once the references panel is open, you can use the search field to
// filter the list or click the [diffInHours[$dtToronto]; // 3
// Now, try to double-click on "diffInHours" or "create" to open
// the References panel.
// Once the references panel is open, you can use the search field to
// filter the list or click the [diffInHours[$dtToronto]; // 3
// Now, try to double-click on "diffInHours" or "create" to open
// the References panel.
// Once the references panel is open, you can use the search field to
// filter the list or click the [diffInHours[$dtToronto]; // 3
// Now, try to double-click on "diffInHours" or "create" to open
// the References panel.
// Once the references panel is open, you can use the search field to
// filter the list or click the [diffInHours[$dtToronto]; // 3
// Now, try to double-click on "diffInHours" or "create" to open
// the References panel.
// Once the references panel is open, you can use the search field to
// filter the list or click the [diffInHours[$dtToronto]; // 3
// Now, try to double-click on "diffInHours" or "create" to open
// the References panel.
// Once the references panel is open, you can use the search field to
// filter the list or click the [diffInHours[$dtToronto]; // 3
// Now, try to double-click on "diffInHours" or "create" to open
// the References panel.
// Once the references panel is open, you can use the search field to
// filter the list or click the [diffInHours[$dtToronto]; // 3
// Now, try to double-click on "diffInHours" or "create" to open
// the References panel.
// Once the references panel is open, you can use the search field to
// filter the list or click the [diffInHours[$dtToronto]; // 3
// Now, try to double-click on "diffInHours" or "create" to open
// the References panel.
// Once the references panel is open, you can use the search field to
// filter the list or click the [diffInHours[$dtToronto]; // 3
// Now, try to double-click on "diffInHours" or "create" to open
// the References panel.
// Once the references panel is open, you can use the search field to
// filter the list or click the [diffInHours[$dtToronto]; // 3
// Now, try to double-click on "diffInHours" or "create" to open
// the References panel.
// Once the references panel is open, you can use the search field to
// filter the list or click the [diffInHours[$dtToronto]; // 3
// Now, try to double-click on "diffInHours" or "create" to open
// the References panel.
// Once the references panel is open, you can use the search field to
// filter the list or click the [diffInHours[$dtToronto]; // 3
// Now, try to double-click on "diffInHours" or "create" to open
// the References panel.
// Once the references panel is open, you can use the search field to
// filter the list or click the [diffInHours[$dtToronto]; // 3
// Now, try to double-click on "diffInHours" or "create" to open
// the References panel.
// Once the references panel is open, you can use the search field to
// filter the list or click the [diffInHours[$dtToronto]; // 3
// Now, try to double-click on "diffInHours" or "create" to open
// the References panel.
// Once the references panel is open, you can use the search field to
// filter the list or click the [diffInHours[$dtToronto]; // 3
// Now, try to double-click on "diffInHours" or "create" to open
// the References panel.
// Once the references panel is open, you can use the search field to
// filter the list or click the [diffInHours[$dtToronto]; // 3
// Now, try to double-click on "diffInHours" or "create" to open
// the References panel.
// Once the references panel is open, you can use the search field to
// filter the list or click the [diffInHours[$dtToronto]; // 3
// Now, try to double-click on "diffInHours" or "create" to open
// the References panel.
// Once the references panel is open, you can use the search field to
// filter the list or click the [diffInHours[$dtToronto]; // 3
// Now, try to double-click on "diffInHours" or "create" to open
// the References panel.
// Once the references panel is open, you can use the search field to
// filter the list or click the [diffInHours[$dtToronto]; // 3
// Now, try to double-click on "diffInHours" or "create" to open
// the References panel.
// Once the references panel is open, you can use the search field to
// filter the list or click the [diffInHours[$dtToronto]; // 3
// Now, try to double-click on "diffInHours" or "create" to open
// the References panel.
// Once the references panel is open, you can use the search field to
// filter the list or click the [diffInHours[$dtToronto]; // 3
// Now, try to double-click on "diffInHours" or "create" to open
// the References panel.
// Once the references panel is open, you can use the search field to
// filter the list or click the [diffInHours[$dtToronto]; // 3
// Now, try to double-click on "diffInHours" or "create" to open
// the References panel.
// Once the references panel is open, you can use the search field to
// filter the list or click the [diffInHours[$dtToronto]; // 3
// Now, try to double-click on "diffInHours" or "create" to open
// the References panel.
// Once the references panel is open, you can use the search field to
// filter the list or click the [diffInHours[$dtToronto]; // 3
// Now, try to double-click on "diffInHours" or "create" to open
// the References panel.
// Once the references panel is open, you can use the search field to
// filter the list or click the [diffInHours[$dtToronto]; // 3
// Now, try to double-click on "diffInHours" or "create" to open
// the References panel.
// Once the references panel is open, you can use the search field to
// filter the list or click the [diffInHours[$dtToronto]; // 3
// Now, try to double-click on "diffInHours" or "create" to open
// the References panel.
// Once the references panel is open, you can use the search field to
// filter the list or click the [diffInHours[$dtToronto]; // 3
// Now, try to double-click on "diffInHours" or "create" to open
// the References panel.
// Once the references panel is open, you can use the search field to
// filter the list or click the [diffInHours[$dtToronto]; // 3
// Now, try to double-click on "diffInHours" or "create" to open
// the References panel.
// Once the references panel is open, you can use the search field to
// filter the list or click the [diffInHours[$dtToronto]; // 3
// Now, try to double-click on "diffInHours" or "create" to open
// the References panel.
// Once the references panel is open, you can use the search field to
// filter the list or click the [diffInHours[$dtToronto]; // 3
// Now, try to double-click on "diffInHours" or "create" to open
// the References panel.
// Once the references panel is open, you can use the search field to
// filter the list or click the [diffInHours[$dtToronto]; // 3
// Now, try to double-click on "diffInHours" or "create" to open
// the References panel.
// Once the references panel is open, you can use the search field to
// filter the list or click the [diffInHours[$dtToronto]; // 3
// Now, try to double-click on "diffInHours" or "create" to open
// the References panel.
// Once the references panel is open, you can use the search field to
// filter the list or click the [diffInHours[$dtToronto]; // 3
// Now, try to double-click on "diffInHours" or "create" to open
// the References panel.
// Once the references panel is open, you can use the search field to
// filter the list or click the [= 0. 5 của đơn vị cuối cùng của khác biệt, đơn vị này sẽ được làm tròn thành giá trị trên
  • Nếu
    $carbon = new Carbon[];                  // equivalent to Carbon::now[]
    $carbon = new Carbon['first day of January 2008', 'America/Vancouver'];
    echo get_class[$carbon];                 // 'Carbon\Carbon'
    
    $carbon = new Carbon[new DateTime['first day of January 2008'], new DateTimeZone['America/Vancouver']]; // equivalent to previous instance
    // You can create Carbon or CarbonImmutable instance from:
    //   - string representation
    //   - integer timestamp
    //   - DateTimeInterface instance [that includes DateTime, DateTimeImmutable or an other Carbon instance]
    // All those are available right in the constructor, other creator methods can be found
    // in the "Reference" panel searching for "create".
    
    05 được bật, các đơn vị còn lại được tính tổng và nếu chúng > 0 của đơn vị cuối cùng của khác biệt, đơn vị này sẽ được làm tròn thành giá trị trên
  • Nếu
    $carbon = new Carbon[];                  // equivalent to Carbon::now[]
    $carbon = new Carbon['first day of January 2008', 'America/Vancouver'];
    echo get_class[$carbon];                 // 'Carbon\Carbon'
    
    $carbon = new Carbon[new DateTime['first day of January 2008'], new DateTimeZone['America/Vancouver']]; // equivalent to previous instance
    // You can create Carbon or CarbonImmutable instance from:
    //   - string representation
    //   - integer timestamp
    //   - DateTimeInterface instance [that includes DateTime, DateTimeImmutable or an other Carbon instance]
    // All those are available right in the constructor, other creator methods can be found
    // in the "Reference" panel searching for "create".
    
    06 được bật, đơn vị khác biệt cuối cùng được làm tròn xuống. Nó không tạo ra sự khác biệt so với hành vi mặc định cho
    $mutable = Carbon::now[];
    $immutable = CarbonImmutable::now[];
    $modifiedMutable = $mutable->add[1, 'day'];
    $modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];
    
    var_dump[$modifiedMutable === $mutable];             // bool[true]
    var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
    var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
    // So it means $mutable and $modifiedMutable are the same object
    // both set to now + 1 day.
    var_dump[$modifiedImmutable === $immutable];         // bool[false]
    var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
    var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
    // While $immutable is still set to now and cannot be changed and
    // $modifiedImmutable is a new instance created from $immutable
    // set to now + 1 day.
    
    $mutable = CarbonImmutable::now[]->toMutable[];
    var_dump[$mutable->isMutable[]];                     // bool[true]
    var_dump[$mutable->isImmutable[]];                   // bool[false]
    $immutable = Carbon::now[]->toImmutable[];
    var_dump[$immutable->isMutable[]];                   // bool[false]
    var_dump[$immutable->isImmutable[]];                 // bool[true]
    
    16 vì khoảng thời gian không thể bị tràn, nhưng tùy chọn này có thể cần thiết khi được sử dụng với
    $carbon = new Carbon[];                  // equivalent to Carbon::now[]
    $carbon = new Carbon['first day of January 2008', 'America/Vancouver'];
    echo get_class[$carbon];                 // 'Carbon\Carbon'
    
    $carbon = new Carbon[new DateTime['first day of January 2008'], new DateTimeZone['America/Vancouver']]; // equivalent to previous instance
    // You can create Carbon or CarbonImmutable instance from:
    //   - string representation
    //   - integer timestamp
    //   - DateTimeInterface instance [that includes DateTime, DateTimeImmutable or an other Carbon instance]
    // All those are available right in the constructor, other creator methods can be found
    // in the "Reference" panel searching for "create".
    
    13 [và các khoảng thời gian không được kiểm tra có thể có 60 phút trở lên, 24 giờ trở lên, v.v. ]. Ví dụ.
    $carbon = new Carbon[];                  // equivalent to Carbon::now[]
    $carbon = new Carbon['first day of January 2008', 'America/Vancouver'];
    echo get_class[$carbon];                 // 'Carbon\Carbon'
    
    $carbon = new Carbon[new DateTime['first day of January 2008'], new DateTimeZone['America/Vancouver']]; // equivalent to previous instance
    // You can create Carbon or CarbonImmutable instance from:
    //   - string representation
    //   - integer timestamp
    //   - DateTimeInterface instance [that includes DateTime, DateTimeImmutable or an other Carbon instance]
    // All those are available right in the constructor, other creator methods can be found
    // in the "Reference" panel searching for "create".
    
    14 trả về
    $carbon = new Carbon[];                  // equivalent to Carbon::now[]
    $carbon = new Carbon['first day of January 2008', 'America/Vancouver'];
    echo get_class[$carbon];                 // 'Carbon\Carbon'
    
    $carbon = new Carbon[new DateTime['first day of January 2008'], new DateTimeZone['America/Vancouver']]; // equivalent to previous instance
    // You can create Carbon or CarbonImmutable instance from:
    //   - string representation
    //   - integer timestamp
    //   - DateTimeInterface instance [that includes DateTime, DateTimeImmutable or an other Carbon instance]
    // All those are available right in the constructor, other creator methods can be found
    // in the "Reference" panel searching for "create".
    
    15 trong khi
    $carbon = new Carbon[];                  // equivalent to Carbon::now[]
    $carbon = new Carbon['first day of January 2008', 'America/Vancouver'];
    echo get_class[$carbon];                 // 'Carbon\Carbon'
    
    $carbon = new Carbon[new DateTime['first day of January 2008'], new DateTimeZone['America/Vancouver']]; // equivalent to previous instance
    // You can create Carbon or CarbonImmutable instance from:
    //   - string representation
    //   - integer timestamp
    //   - DateTimeInterface instance [that includes DateTime, DateTimeImmutable or an other Carbon instance]
    // All those are available right in the constructor, other creator methods can be found
    // in the "Reference" panel searching for "create".
    
    16 trả về
    $carbon = new Carbon[];                  // equivalent to Carbon::now[]
    $carbon = new Carbon['first day of January 2008', 'America/Vancouver'];
    echo get_class[$carbon];                 // 'Carbon\Carbon'
    
    $carbon = new Carbon[new DateTime['first day of January 2008'], new DateTimeZone['America/Vancouver']]; // equivalent to previous instance
    // You can create Carbon or CarbonImmutable instance from:
    //   - string representation
    //   - integer timestamp
    //   - DateTimeInterface instance [that includes DateTime, DateTimeImmutable or an other Carbon instance]
    // All those are available right in the constructor, other creator methods can be found
    // in the "Reference" panel searching for "create".
    
    17
  • $carbon = new Carbon[];                  // equivalent to Carbon::now[]
    $carbon = new Carbon['first day of January 2008', 'America/Vancouver'];
    echo get_class[$carbon];                 // 'Carbon\Carbon'
    
    $carbon = new Carbon[new DateTime['first day of January 2008'], new DateTimeZone['America/Vancouver']]; // equivalent to previous instance
    // You can create Carbon or CarbonImmutable instance from:
    //   - string representation
    //   - integer timestamp
    //   - DateTimeInterface instance [that includes DateTime, DateTimeImmutable or an other Carbon instance]
    // All those are available right in the constructor, other creator methods can be found
    // in the "Reference" panel searching for "create".
    
    03 [được bật theo mặc định]. biến khác biệt trống thành 1 giây
  • $carbon = new Carbon[];                  // equivalent to Carbon::now[]
    $carbon = new Carbon['first day of January 2008', 'America/Vancouver'];
    echo get_class[$carbon];                 // 'Carbon\Carbon'
    
    $carbon = new Carbon[new DateTime['first day of January 2008'], new DateTimeZone['America/Vancouver']]; // equivalent to previous instance
    // You can create Carbon or CarbonImmutable instance from:
    //   - string representation
    //   - integer timestamp
    //   - DateTimeInterface instance [that includes DateTime, DateTimeImmutable or an other Carbon instance]
    // All those are available right in the constructor, other creator methods can be found
    // in the "Reference" panel searching for "create".
    
    19 bị tắt theo mặc định]. biến diff từ bây giờ đến bây giờ thành "ngay bây giờ"
  • $carbon = new Carbon[];                  // equivalent to Carbon::now[]
    $carbon = new Carbon['first day of January 2008', 'America/Vancouver'];
    echo get_class[$carbon];                 // 'Carbon\Carbon'
    
    $carbon = new Carbon[new DateTime['first day of January 2008'], new DateTimeZone['America/Vancouver']]; // equivalent to previous instance
    // You can create Carbon or CarbonImmutable instance from:
    //   - string representation
    //   - integer timestamp
    //   - DateTimeInterface instance [that includes DateTime, DateTimeImmutable or an other Carbon instance]
    // All those are available right in the constructor, other creator methods can be found
    // in the "Reference" panel searching for "create".
    
    20 [disabled by default]. turns "1 day from now/ago" to "yesterday/tomorrow"
  • $carbon = new Carbon[];                  // equivalent to Carbon::now[]
    $carbon = new Carbon['first day of January 2008', 'America/Vancouver'];
    echo get_class[$carbon];                 // 'Carbon\Carbon'
    
    $carbon = new Carbon[new DateTime['first day of January 2008'], new DateTimeZone['America/Vancouver']]; // equivalent to previous instance
    // You can create Carbon or CarbonImmutable instance from:
    //   - string representation
    //   - integer timestamp
    //   - DateTimeInterface instance [that includes DateTime, DateTimeImmutable or an other Carbon instance]
    // All those are available right in the constructor, other creator methods can be found
    // in the "Reference" panel searching for "create".
    
    21 [disabled by default]. turns "2 days from now/ago" to "before yesterday/after
  • $carbon = new Carbon[];                  // equivalent to Carbon::now[]
    $carbon = new Carbon['first day of January 2008', 'America/Vancouver'];
    echo get_class[$carbon];                 // 'Carbon\Carbon'
    
    $carbon = new Carbon[new DateTime['first day of January 2008'], new DateTimeZone['America/Vancouver']]; // equivalent to previous instance
    // You can create Carbon or CarbonImmutable instance from:
    //   - string representation
    //   - integer timestamp
    //   - DateTimeInterface instance [that includes DateTime, DateTimeImmutable or an other Carbon instance]
    // All those are available right in the constructor, other creator methods can be found
    // in the "Reference" panel searching for "create".
    
    22 [disabled by default]. will keep only the first sequence of units of the interval, for example if the diff would have been "2 weeks 1 day 34 minutes 12 seconds" as day and minute are not consecutive units, you will get. "2 weeks 1 day"
  • Use the pipe operator to enable/disable multiple option at once, example.

    $carbon = new Carbon[];                  // equivalent to Carbon::now[]
    $carbon = new Carbon['first day of January 2008', 'America/Vancouver'];
    echo get_class[$carbon];                 // 'Carbon\Carbon'
    
    $carbon = new Carbon[new DateTime['first day of January 2008'], new DateTimeZone['America/Vancouver']]; // equivalent to previous instance
    // You can create Carbon or CarbonImmutable instance from:
    //   - string representation
    //   - integer timestamp
    //   - DateTimeInterface instance [that includes DateTime, DateTimeImmutable or an other Carbon instance]
    // All those are available right in the constructor, other creator methods can be found
    // in the "Reference" panel searching for "create".
    
    23

    You also can use

    $carbon = new Carbon[];                  // equivalent to Carbon::now[]
    $carbon = new Carbon['first day of January 2008', 'America/Vancouver'];
    echo get_class[$carbon];                 // 'Carbon\Carbon'
    
    $carbon = new Carbon[new DateTime['first day of January 2008'], new DateTimeZone['America/Vancouver']]; // equivalent to previous instance
    // You can create Carbon or CarbonImmutable instance from:
    //   - string representation
    //   - integer timestamp
    //   - DateTimeInterface instance [that includes DateTime, DateTimeImmutable or an other Carbon instance]
    // All those are available right in the constructor, other creator methods can be found
    // in the "Reference" panel searching for "create".
    
    24,
    $carbon = new Carbon[];                  // equivalent to Carbon::now[]
    $carbon = new Carbon['first day of January 2008', 'America/Vancouver'];
    echo get_class[$carbon];                 // 'Carbon\Carbon'
    
    $carbon = new Carbon[new DateTime['first day of January 2008'], new DateTimeZone['America/Vancouver']]; // equivalent to previous instance
    // You can create Carbon or CarbonImmutable instance from:
    //   - string representation
    //   - integer timestamp
    //   - DateTimeInterface instance [that includes DateTime, DateTimeImmutable or an other Carbon instance]
    // All those are available right in the constructor, other creator methods can be found
    // in the "Reference" panel searching for "create".
    
    25,
    $carbon = new Carbon[];                  // equivalent to Carbon::now[]
    $carbon = new Carbon['first day of January 2008', 'America/Vancouver'];
    echo get_class[$carbon];                 // 'Carbon\Carbon'
    
    $carbon = new Carbon[new DateTime['first day of January 2008'], new DateTimeZone['America/Vancouver']]; // equivalent to previous instance
    // You can create Carbon or CarbonImmutable instance from:
    //   - string representation
    //   - integer timestamp
    //   - DateTimeInterface instance [that includes DateTime, DateTimeImmutable or an other Carbon instance]
    // All those are available right in the constructor, other creator methods can be found
    // in the "Reference" panel searching for "create".
    
    26 to change the default options and
    $carbon = new Carbon[];                  // equivalent to Carbon::now[]
    $carbon = new Carbon['first day of January 2008', 'America/Vancouver'];
    echo get_class[$carbon];                 // 'Carbon\Carbon'
    
    $carbon = new Carbon[new DateTime['first day of January 2008'], new DateTimeZone['America/Vancouver']]; // equivalent to previous instance
    // You can create Carbon or CarbonImmutable instance from:
    //   - string representation
    //   - integer timestamp
    //   - DateTimeInterface instance [that includes DateTime, DateTimeImmutable or an other Carbon instance]
    // All those are available right in the constructor, other creator methods can be found
    // in the "Reference" panel searching for "create".
    
    27 to get default options but you should avoid using it as being static it may conflict with calls from other code parts/third-party libraries

    Aliases and reverse methods are provided for semantic purpose

    • $carbon = new Carbon[];                  // equivalent to Carbon::now[]
      $carbon = new Carbon['first day of January 2008', 'America/Vancouver'];
      echo get_class[$carbon];                 // 'Carbon\Carbon'
      
      $carbon = new Carbon[new DateTime['first day of January 2008'], new DateTimeZone['America/Vancouver']]; // equivalent to previous instance
      // You can create Carbon or CarbonImmutable instance from:
      //   - string representation
      //   - integer timestamp
      //   - DateTimeInterface instance [that includes DateTime, DateTimeImmutable or an other Carbon instance]
      // All those are available right in the constructor, other creator methods can be found
      // in the "Reference" panel searching for "create".
      
      28 [alias of diffForHumans]
    • $carbon = new Carbon[];                  // equivalent to Carbon::now[]
      $carbon = new Carbon['first day of January 2008', 'America/Vancouver'];
      echo get_class[$carbon];                 // 'Carbon\Carbon'
      
      $carbon = new Carbon[new DateTime['first day of January 2008'], new DateTimeZone['America/Vancouver']]; // equivalent to previous instance
      // You can create Carbon or CarbonImmutable instance from:
      //   - string representation
      //   - integer timestamp
      //   - DateTimeInterface instance [that includes DateTime, DateTimeImmutable or an other Carbon instance]
      // All those are available right in the constructor, other creator methods can be found
      // in the "Reference" panel searching for "create".
      
      29 [alias of diffForHumans]
    • $carbon = new Carbon[];                  // equivalent to Carbon::now[]
      $carbon = new Carbon['first day of January 2008', 'America/Vancouver'];
      echo get_class[$carbon];                 // 'Carbon\Carbon'
      
      $carbon = new Carbon[new DateTime['first day of January 2008'], new DateTimeZone['America/Vancouver']]; // equivalent to previous instance
      // You can create Carbon or CarbonImmutable instance from:
      //   - string representation
      //   - integer timestamp
      //   - DateTimeInterface instance [that includes DateTime, DateTimeImmutable or an other Carbon instance]
      // All those are available right in the constructor, other creator methods can be found
      // in the "Reference" panel searching for "create".
      
      30 [inverse result, swap before and future diff]
    • $carbon = new Carbon[];                  // equivalent to Carbon::now[]
      $carbon = new Carbon['first day of January 2008', 'America/Vancouver'];
      echo get_class[$carbon];                 // 'Carbon\Carbon'
      
      $carbon = new Carbon[new DateTime['first day of January 2008'], new DateTimeZone['America/Vancouver']]; // equivalent to previous instance
      // You can create Carbon or CarbonImmutable instance from:
      //   - string representation
      //   - integer timestamp
      //   - DateTimeInterface instance [that includes DateTime, DateTimeImmutable or an other Carbon instance]
      // All those are available right in the constructor, other creator methods can be found
      // in the "Reference" panel searching for "create".
      
      31 [alias of to]
    • $carbon = new Carbon[];                  // equivalent to Carbon::now[]
      $carbon = new Carbon['first day of January 2008', 'America/Vancouver'];
      echo get_class[$carbon];                 // 'Carbon\Carbon'
      
      $carbon = new Carbon[new DateTime['first day of January 2008'], new DateTimeZone['America/Vancouver']]; // equivalent to previous instance
      // You can create Carbon or CarbonImmutable instance from:
      //   - string representation
      //   - integer timestamp
      //   - DateTimeInterface instance [that includes DateTime, DateTimeImmutable or an other Carbon instance]
      // All those are available right in the constructor, other creator methods can be found
      // in the "Reference" panel searching for "create".
      
      32 [alias of from with first argument omitted unless the first argument is a
      $carbon = new Carbon[];                  // equivalent to Carbon::now[]
      $carbon = new Carbon['first day of January 2008', 'America/Vancouver'];
      echo get_class[$carbon];                 // 'Carbon\Carbon'
      
      $carbon = new Carbon[new DateTime['first day of January 2008'], new DateTimeZone['America/Vancouver']]; // equivalent to previous instance
      // You can create Carbon or CarbonImmutable instance from:
      //   - string representation
      //   - integer timestamp
      //   - DateTimeInterface instance [that includes DateTime, DateTimeImmutable or an other Carbon instance]
      // All those are available right in the constructor, other creator methods can be found
      // in the "Reference" panel searching for "create".
      
      33, now used instead], for semantic usage. produce an "3 hours from now"-like string with dates in the future
    • $carbon = new Carbon[];                  // equivalent to Carbon::now[]
      $carbon = new Carbon['first day of January 2008', 'America/Vancouver'];
      echo get_class[$carbon];                 // 'Carbon\Carbon'
      
      $carbon = new Carbon[new DateTime['first day of January 2008'], new DateTimeZone['America/Vancouver']]; // equivalent to previous instance
      // You can create Carbon or CarbonImmutable instance from:
      //   - string representation
      //   - integer timestamp
      //   - DateTimeInterface instance [that includes DateTime, DateTimeImmutable or an other Carbon instance]
      // All those are available right in the constructor, other creator methods can be found
      // in the "Reference" panel searching for "create".
      
      34 [alias of fromNow], for semantic usage. produce an "3 hours ago"-like string with dates in the past
    • $carbon = new Carbon[];                  // equivalent to Carbon::now[]
      $carbon = new Carbon['first day of January 2008', 'America/Vancouver'];
      echo get_class[$carbon];                 // 'Carbon\Carbon'
      
      $carbon = new Carbon[new DateTime['first day of January 2008'], new DateTimeZone['America/Vancouver']]; // equivalent to previous instance
      // You can create Carbon or CarbonImmutable instance from:
      //   - string representation
      //   - integer timestamp
      //   - DateTimeInterface instance [that includes DateTime, DateTimeImmutable or an other Carbon instance]
      // All those are available right in the constructor, other creator methods can be found
      // in the "Reference" panel searching for "create".
      
      35 [alias of to with first argument omitted, now used instead]
    • $carbon = new Carbon[];                  // equivalent to Carbon::now[]
      $carbon = new Carbon['first day of January 2008', 'America/Vancouver'];
      echo get_class[$carbon];                 // 'Carbon\Carbon'
      
      $carbon = new Carbon[new DateTime['first day of January 2008'], new DateTimeZone['America/Vancouver']]; // equivalent to previous instance
      // You can create Carbon or CarbonImmutable instance from:
      //   - string representation
      //   - integer timestamp
      //   - DateTimeInterface instance [that includes DateTime, DateTimeImmutable or an other Carbon instance]
      // All those are available right in the constructor, other creator methods can be found
      // in the "Reference" panel searching for "create".
      
      36 gọi diffForHumans với các tùy chọn
      $carbon = new Carbon[];                  // equivalent to Carbon::now[]
      $carbon = new Carbon['first day of January 2008', 'America/Vancouver'];
      echo get_class[$carbon];                 // 'Carbon\Carbon'
      
      $carbon = new Carbon[new DateTime['first day of January 2008'], new DateTimeZone['America/Vancouver']]; // equivalent to previous instance
      // You can create Carbon or CarbonImmutable instance from:
      //   - string representation
      //   - integer timestamp
      //   - DateTimeInterface instance [that includes DateTime, DateTimeImmutable or an other Carbon instance]
      // All those are available right in the constructor, other creator methods can be found
      // in the "Reference" panel searching for "create".
      
      37 [được phân tách bằng hôn mê],
      $carbon = new Carbon[];                  // equivalent to Carbon::now[]
      $carbon = new Carbon['first day of January 2008', 'America/Vancouver'];
      echo get_class[$carbon];                 // 'Carbon\Carbon'
      
      $carbon = new Carbon[new DateTime['first day of January 2008'], new DateTimeZone['America/Vancouver']]; // equivalent to previous instance
      // You can create Carbon or CarbonImmutable instance from:
      //   - string representation
      //   - integer timestamp
      //   - DateTimeInterface instance [that includes DateTime, DateTimeImmutable or an other Carbon instance]
      // All those are available right in the constructor, other creator methods can be found
      // in the "Reference" panel searching for "create".
      
      38 [không có từ "trước"/"từ bây giờ"/"trước"/"sau"],
      $carbon = new Carbon[];                  // equivalent to Carbon::now[]
      $carbon = new Carbon['first day of January 2008', 'America/Vancouver'];
      echo get_class[$carbon];                 // 'Carbon\Carbon'
      
      $carbon = new Carbon[new DateTime['first day of January 2008'], new DateTimeZone['America/Vancouver']]; // equivalent to previous instance
      // You can create Carbon or CarbonImmutable instance from:
      //   - string representation
      //   - integer timestamp
      //   - DateTimeInterface instance [that includes DateTime, DateTimeImmutable or an other Carbon instance]
      // All those are available right in the constructor, other creator methods can be found
      // in the "Reference" panel searching for "create".
      
      39 [không có từ "ngay bây giờ"/"hôm qua"/"ngày mai"

    Nhóm các phương thức này thực hiện các sửa đổi hữu ích đối với phiên bản hiện tại. Hầu hết trong số họ là tự giải thích từ tên của họ. hoặc ít nhất là nên. Bạn cũng sẽ nhận thấy rằng các phương thức startOfXXX[], next[] và previous[] đặt thời gian là 00. 00. 00 và các phương thức endOfXXX[] đặt thời gian thành 23. 59. 59 cho đơn vị lớn hơn ngày

    Điều duy nhất hơi khác một chút là chức năng

    $carbon = new Carbon[];                  // equivalent to Carbon::now[]
    $carbon = new Carbon['first day of January 2008', 'America/Vancouver'];
    echo get_class[$carbon];                 // 'Carbon\Carbon'
    
    $carbon = new Carbon[new DateTime['first day of January 2008'], new DateTimeZone['America/Vancouver']]; // equivalent to previous instance
    // You can create Carbon or CarbonImmutable instance from:
    //   - string representation
    //   - integer timestamp
    //   - DateTimeInterface instance [that includes DateTime, DateTimeImmutable or an other Carbon instance]
    // All those are available right in the constructor, other creator methods can be found
    // in the "Reference" panel searching for "create".
    
    41. Nó di chuyển phiên bản của bạn đến ngày ở giữa giữa chính nó và đối số Carbon được cung cấp

    Phương pháp

    $dtToronto = Carbon::create[2012, 1, 1, 0, 0, 0, 'America/Toronto'];
    $dtVancouver = Carbon::create[2012, 1, 1, 0, 0, 0, 'America/Vancouver'];
    // Try to replace the 4th number [hours] or the last argument [timezone] with
    // Europe/Paris for example and see the actual result on the right hand.
    // It's alive!
    
    echo $dtVancouver->diffInHours[$dtToronto]; // 3
    // Now, try to double-click on "diffInHours" or "create" to open
    // the References panel.
    // Once the references panel is open, you can use the search field to
    // filter the list or click the [diffInHours[$dtToronto]; // 3
    // Now, try to double-click on "diffInHours" or "create" to open
    // the References panel.
    // Once the references panel is open, you can use the search field to
    // filter the list or click the [diffInHours[$dtToronto]; // 3
    // Now, try to double-click on "diffInHours" or "create" to open
    // the References panel.
    // Once the references panel is open, you can use the search field to
    // filter the list or click the [add[1, 'day'];
    $modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];
    
    var_dump[$modifiedMutable === $mutable];             // bool[true]
    var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
    var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
    // So it means $mutable and $modifiedMutable are the same object
    // both set to now + 1 day.
    var_dump[$modifiedImmutable === $immutable];         // bool[false]
    var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
    var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
    // While $immutable is still set to now and cannot be changed and
    // $modifiedImmutable is a new instance created from $immutable
    // set to now + 1 day.
    
    $mutable = CarbonImmutable::now[]->toMutable[];
    var_dump[$mutable->isMutable[]];                     // bool[true]
    var_dump[$mutable->isImmutable[]];                   // bool[false]
    $immutable = Carbon::now[]->toImmutable[];
    var_dump[$immutable->isMutable[]];                   // bool[false]
    var_dump[$immutable->isImmutable[]];                 // bool[true]
    
    09 thân thiện

    use Carbon\Carbon;
    18

    Và ngược lại, bạn có thể trích xuất một

    $dtToronto = Carbon::create[2012, 1, 1, 0, 0, 0, 'America/Toronto'];
    $dtVancouver = Carbon::create[2012, 1, 1, 0, 0, 0, 'America/Vancouver'];
    // Try to replace the 4th number [hours] or the last argument [timezone] with
    // Europe/Paris for example and see the actual result on the right hand.
    // It's alive!
    
    echo $dtVancouver->diffInHours[$dtToronto]; // 3
    // Now, try to double-click on "diffInHours" or "create" to open
    // the References panel.
    // Once the references panel is open, you can use the search field to
    // filter the list or click the [diffInHours[$dtToronto]; // 3
    // Now, try to double-click on "diffInHours" or "create" to open
    // the References panel.
    // Once the references panel is open, you can use the search field to
    // filter the list or click the [diffInHours[$dtToronto]; // 3
    // Now, try to double-click on "diffInHours" or "create" to open
    // the References panel.
    // Once the references panel is open, you can use the search field to
    // filter the list or click the [diffInHours[$dtToronto]; // 3
    // Now, try to double-click on "diffInHours" or "create" to open
    // the References panel.
    // Once the references panel is open, you can use the search field to
    // filter the list or click the [tzName;             // Europe/London
    echo "\n";
    
    // or to create a date with a custom fixed timezone offset
    $date = Carbon::now['+13:30'];
    echo $date->tzName;                      // +13:30
    echo "\n";
    
    // Get/set minutes offset from UTC
    echo $date->utcOffset[];                 // 810
    echo "\n";
    
    $date->utcOffset[180];
    
    echo $date->tzName;                      // +03:00
    echo "\n";
    echo $date->utcOffset[];                 // 180
    
    01 và
    $now = Carbon::now[]; // will use timezone as set with date_default_timezone_set
    // PS: we recommend you to work with UTC as default timezone and only use
    // other timezones [such as the user timezone] on display
    
    $nowInLondonTz = Carbon::now[new DateTimeZone['Europe/London']];
    
    // or just pass the timezone as a string
    $nowInLondonTz = Carbon::now['Europe/London'];
    echo $nowInLondonTz->tzName;             // Europe/London
    echo "\n";
    
    // or to create a date with a custom fixed timezone offset
    $date = Carbon::now['+13:30'];
    echo $date->tzName;                      // +13:30
    echo "\n";
    
    // Get/set minutes offset from UTC
    echo $date->utcOffset[];                 // 810
    echo "\n";
    
    $date->utcOffset[180];
    
    echo $date->tzName;                      // +03:00
    echo "\n";
    echo $date->utcOffset[];                 // 180
    
    02

    use Carbon\Carbon;
    33

    Ngoài các khoảng thời gian cố định, Khoảng thời gian động có thể được mô tả bằng chức năng bước từ ngày này sang ngày khác

    use Carbon\Carbon;
    34

    Bạn có thể truy cập và sửa đổi định nghĩa bước đóng bằng cách sử dụng

    $now = Carbon::now[]; // will use timezone as set with date_default_timezone_set
    // PS: we recommend you to work with UTC as default timezone and only use
    // other timezones [such as the user timezone] on display
    
    $nowInLondonTz = Carbon::now[new DateTimeZone['Europe/London']];
    
    // or just pass the timezone as a string
    $nowInLondonTz = Carbon::now['Europe/London'];
    echo $nowInLondonTz->tzName;             // Europe/London
    echo "\n";
    
    // or to create a date with a custom fixed timezone offset
    $date = Carbon::now['+13:30'];
    echo $date->tzName;                      // +13:30
    echo "\n";
    
    // Get/set minutes offset from UTC
    echo $date->utcOffset[];                 // 810
    echo "\n";
    
    $date->utcOffset[180];
    
    echo $date->tzName;                      // +03:00
    echo "\n";
    echo $date->utcOffset[];                 // 180
    
    03 và
    $now = Carbon::now[]; // will use timezone as set with date_default_timezone_set
    // PS: we recommend you to work with UTC as default timezone and only use
    // other timezones [such as the user timezone] on display
    
    $nowInLondonTz = Carbon::now[new DateTimeZone['Europe/London']];
    
    // or just pass the timezone as a string
    $nowInLondonTz = Carbon::now['Europe/London'];
    echo $nowInLondonTz->tzName;             // Europe/London
    echo "\n";
    
    // or to create a date with a custom fixed timezone offset
    $date = Carbon::now['+13:30'];
    echo $date->tzName;                      // +13:30
    echo "\n";
    
    // Get/set minutes offset from UTC
    echo $date->utcOffset[];                 // 810
    echo "\n";
    
    $date->utcOffset[180];
    
    echo $date->tzName;                      // +03:00
    echo "\n";
    echo $date->utcOffset[];                 // 180
    
    04 [trình thiết lập có thể lấy
    use Carbon\Carbon;
    86 để xóa nó để nó trở thành một khoảng thời gian cố định đơn giản. Và miễn là khoảng thời gian có một bước, nó sẽ được ưu tiên hơn tất cả các đơn vị cố định mà nó chứa

    Bạn có thể gọi

    $now = Carbon::now[]; // will use timezone as set with date_default_timezone_set
    // PS: we recommend you to work with UTC as default timezone and only use
    // other timezones [such as the user timezone] on display
    
    $nowInLondonTz = Carbon::now[new DateTimeZone['Europe/London']];
    
    // or just pass the timezone as a string
    $nowInLondonTz = Carbon::now['Europe/London'];
    echo $nowInLondonTz->tzName;             // Europe/London
    echo "\n";
    
    // or to create a date with a custom fixed timezone offset
    $date = Carbon::now['+13:30'];
    echo $date->tzName;                      // +13:30
    echo "\n";
    
    // Get/set minutes offset from UTC
    echo $date->utcOffset[];                 // 810
    echo "\n";
    
    $date->utcOffset[180];
    
    echo $date->tzName;                      // +03:00
    echo "\n";
    echo $date->utcOffset[];                 // 180
    
    06 để áp dụng khoảng thời gian động hoặc tĩnh hiện tại cho một ngày [
    $dtToronto = Carbon::create[2012, 1, 1, 0, 0, 0, 'America/Toronto'];
    $dtVancouver = Carbon::create[2012, 1, 1, 0, 0, 0, 'America/Vancouver'];
    // Try to replace the 4th number [hours] or the last argument [timezone] with
    // Europe/Paris for example and see the actual result on the right hand.
    // It's alive!
    
    echo $dtVancouver->diffInHours[$dtToronto]; // 3
    // Now, try to double-click on "diffInHours" or "create" to open
    // the References panel.
    // Once the references panel is open, you can use the search field to
    // filter the list or click the [add[1, 'day'];
    $modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];
    
    var_dump[$modifiedMutable === $mutable];             // bool[true]
    var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
    var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
    // So it means $mutable and $modifiedMutable are the same object
    // both set to now + 1 day.
    var_dump[$modifiedImmutable === $immutable];         // bool[false]
    var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
    var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
    // While $immutable is still set to now and cannot be changed and
    // $modifiedImmutable is a new instance created from $immutable
    // set to now + 1 day.
    
    $mutable = CarbonImmutable::now[]->toMutable[];
    var_dump[$mutable->isMutable[]];                     // bool[true]
    var_dump[$mutable->isImmutable[]];                   // bool[false]
    $immutable = Carbon::now[]->toImmutable[];
    var_dump[$immutable->isMutable[]];                   // bool[false]
    var_dump[$immutable->isImmutable[]];                 // bool[true]
    
    08 hoặc những ngày không thay đổi] một cách tích cực [hoặc chuyển một cách tiêu cực
    $dtToronto = Carbon::create[2012, 1, 1, 0, 0, 0, 'America/Toronto'];
    $dtVancouver = Carbon::create[2012, 1, 1, 0, 0, 0, 'America/Vancouver'];
    // Try to replace the 4th number [hours] or the last argument [timezone] with
    // Europe/Paris for example and see the actual result on the right hand.
    // It's alive!
    
    echo $dtVancouver->diffInHours[$dtToronto]; // 3
    // Now, try to double-click on "diffInHours" or "create" to open
    // the References panel.
    // Once the references panel is open, you can use the search field to
    // filter the list or click the [tzName;             // Europe/London
    echo "\n";
    
    // or to create a date with a custom fixed timezone offset
    $date = Carbon::now['+13:30'];
    echo $date->tzName;                      // +13:30
    echo "\n";
    
    // Get/set minutes offset from UTC
    echo $date->utcOffset[];                 // 810
    echo "\n";
    
    $date->utcOffset[180];
    
    echo $date->tzName;                      // +03:00
    echo "\n";
    echo $date->utcOffset[];                 // 180
    
    10 với các đối số bổ sung

    Tôi nghe bạn hỏi phiên bản CarbonPeriod là gì. Ồ. Chuyển đổi hoàn hảo sang chương tiếp theo của chúng tôi

    CarbonPeriod là phiên bản DatePeriod thân thiện với con người với nhiều phím tắt

    use Carbon\Carbon;
    37

    Một CarbonPeriod có thể được xây dựng theo một số cách

    • ngày bắt đầu, ngày kết thúc và khoảng thời gian tùy chọn [theo mặc định là 1 ngày],
    • ngày bắt đầu, số lần lặp lại và khoảng thời gian tùy chọn,
    • thông số kỹ thuật khoảng ISO 8601,
    • từ một
      $now = Carbon::now[]; // will use timezone as set with date_default_timezone_set
      // PS: we recommend you to work with UTC as default timezone and only use
      // other timezones [such as the user timezone] on display
      
      $nowInLondonTz = Carbon::now[new DateTimeZone['Europe/London']];
      
      // or just pass the timezone as a string
      $nowInLondonTz = Carbon::now['Europe/London'];
      echo $nowInLondonTz->tzName;             // Europe/London
      echo "\n";
      
      // or to create a date with a custom fixed timezone offset
      $date = Carbon::now['+13:30'];
      echo $date->tzName;                      // +13:30
      echo "\n";
      
      // Get/set minutes offset from UTC
      echo $date->utcOffset[];                 // 810
      echo "\n";
      
      $date->utcOffset[180];
      
      echo $date->tzName;                      // +03:00
      echo "\n";
      echo $date->utcOffset[];                 // 180
      
      11 hoặc
      $carbon = new Carbon[];                  // equivalent to Carbon::now[]
      $carbon = new Carbon['first day of January 2008', 'America/Vancouver'];
      echo get_class[$carbon];                 // 'Carbon\Carbon'
      
      $carbon = new Carbon[new DateTime['first day of January 2008'], new DateTimeZone['America/Vancouver']]; // equivalent to previous instance
      // You can create Carbon or CarbonImmutable instance from:
      //   - string representation
      //   - integer timestamp
      //   - DateTimeInterface instance [that includes DateTime, DateTimeImmutable or an other Carbon instance]
      // All those are available right in the constructor, other creator methods can be found
      // in the "Reference" panel searching for "create".
      
      61 khác bằng cách sử dụng
      $now = Carbon::now[]; // will use timezone as set with date_default_timezone_set
      // PS: we recommend you to work with UTC as default timezone and only use
      // other timezones [such as the user timezone] on display
      
      $nowInLondonTz = Carbon::now[new DateTimeZone['Europe/London']];
      
      // or just pass the timezone as a string
      $nowInLondonTz = Carbon::now['Europe/London'];
      echo $nowInLondonTz->tzName;             // Europe/London
      echo "\n";
      
      // or to create a date with a custom fixed timezone offset
      $date = Carbon::now['+13:30'];
      echo $date->tzName;                      // +13:30
      echo "\n";
      
      // Get/set minutes offset from UTC
      echo $date->utcOffset[];                 // 810
      echo "\n";
      
      $date->utcOffset[180];
      
      echo $date->tzName;                      // +03:00
      echo "\n";
      echo $date->utcOffset[];                 // 180
      
      13 hoặc đơn giản là sử dụng
      $now = Carbon::now[]; // will use timezone as set with date_default_timezone_set
      // PS: we recommend you to work with UTC as default timezone and only use
      // other timezones [such as the user timezone] on display
      
      $nowInLondonTz = Carbon::now[new DateTimeZone['Europe/London']];
      
      // or just pass the timezone as a string
      $nowInLondonTz = Carbon::now['Europe/London'];
      echo $nowInLondonTz->tzName;             // Europe/London
      echo "\n";
      
      // or to create a date with a custom fixed timezone offset
      $date = Carbon::now['+13:30'];
      echo $date->tzName;                      // +13:30
      echo "\n";
      
      // Get/set minutes offset from UTC
      echo $date->utcOffset[];                 // 810
      echo "\n";
      
      $date->utcOffset[180];
      
      echo $date->tzName;                      // +03:00
      echo "\n";
      echo $date->utcOffset[];                 // 180
      
      14

    Ngày có thể được cung cấp dưới dạng phiên bản DateTime/Carbon, các chuỗi tuyệt đối như "2007-10-15 15. 00" hoặc chuỗi tương đối, ví dụ "thứ hai tới". Khoảng thời gian có thể được cung cấp dưới dạng ví dụ DateInterval/CarbonInterval, thông số kỹ thuật khoảng thời gian ISO 8601 như "P4D" hoặc chuỗi có thể đọc được của con người, ví dụ: "4 ngày"

    Hàm tạo mặc định và các phương thức

    use Carbon\Carbon;
    83 rất dễ hiểu về loại đối số và thứ tự, vì vậy nếu bạn muốn chính xác hơn thì nên sử dụng cú pháp thông thạo. Mặt khác, bạn có thể chuyển mảng giá trị động cho
    $now = Carbon::now[]; // will use timezone as set with date_default_timezone_set
    // PS: we recommend you to work with UTC as default timezone and only use
    // other timezones [such as the user timezone] on display
    
    $nowInLondonTz = Carbon::now[new DateTimeZone['Europe/London']];
    
    // or just pass the timezone as a string
    $nowInLondonTz = Carbon::now['Europe/London'];
    echo $nowInLondonTz->tzName;             // Europe/London
    echo "\n";
    
    // or to create a date with a custom fixed timezone offset
    $date = Carbon::now['+13:30'];
    echo $date->tzName;                      // +13:30
    echo "\n";
    
    // Get/set minutes offset from UTC
    echo $date->utcOffset[];                 // 810
    echo "\n";
    
    $date->utcOffset[180];
    
    echo $date->tzName;                      // +03:00
    echo "\n";
    echo $date->utcOffset[];                 // 180
    
    16, nó sẽ thực hiện công việc xây dựng một thể hiện mới với mảng đã cho dưới dạng danh sách các đối số

    CarbonPeriod triển khai giao diện Iterator. Điều đó có nghĩa là nó có thể được chuyển trực tiếp đến vòng lặp

    $now = Carbon::now[]; // will use timezone as set with date_default_timezone_set
    // PS: we recommend you to work with UTC as default timezone and only use
    // other timezones [such as the user timezone] on display
    
    $nowInLondonTz = Carbon::now[new DateTimeZone['Europe/London']];
    
    // or just pass the timezone as a string
    $nowInLondonTz = Carbon::now['Europe/London'];
    echo $nowInLondonTz->tzName;             // Europe/London
    echo "\n";
    
    // or to create a date with a custom fixed timezone offset
    $date = Carbon::now['+13:30'];
    echo $date->tzName;                      // +13:30
    echo "\n";
    
    // Get/set minutes offset from UTC
    echo $date->utcOffset[];                 // 810
    echo "\n";
    
    $date->utcOffset[180];
    
    echo $date->tzName;                      // +03:00
    echo "\n";
    echo $date->utcOffset[];                 // 180
    
    17

    use Carbon\Carbon;
    38

    Các tham số có thể được sửa đổi trong quá trình lặp lại

    use Carbon\Carbon;
    39

    Giống như DatePeriod, CarbonPeriod hỗ trợ

    Lưu ý rằng DatePeriod gốc coi số lần lặp lại là số lần lặp lại khoảng thời gian. Do đó, nó sẽ cho một kết quả ít hơn khi loại trừ ngày bắt đầu. Việc giới thiệu các bộ lọc tùy chỉnh trong CarbonPeriod khiến việc biết số lượng kết quả trở nên khó khăn hơn. Vì lý do đó, chúng tôi đã thay đổi cách triển khai một chút và các lần lặp lại được coi là giới hạn chung cho số ngày được trả về

    use Carbon\Carbon;
    40

    Bạn có thể truy xuất dữ liệu từ khoảng thời gian với nhiều getters

    use Carbon\Carbon;
    41

    Các getters bổ sung cho phép bạn truy cập các kết quả dưới dạng một mảng

    use Carbon\Carbon;
    42

    Lưu ý rằng nếu bạn có ý định làm việc bằng cách sử dụng các hàm trên, bạn nên lưu trữ kết quả của lệnh gọi

    $now = Carbon::now[]; // will use timezone as set with date_default_timezone_set
    // PS: we recommend you to work with UTC as default timezone and only use
    // other timezones [such as the user timezone] on display
    
    $nowInLondonTz = Carbon::now[new DateTimeZone['Europe/London']];
    
    // or just pass the timezone as a string
    $nowInLondonTz = Carbon::now['Europe/London'];
    echo $nowInLondonTz->tzName;             // Europe/London
    echo "\n";
    
    // or to create a date with a custom fixed timezone offset
    $date = Carbon::now['+13:30'];
    echo $date->tzName;                      // +13:30
    echo "\n";
    
    // Get/set minutes offset from UTC
    echo $date->utcOffset[];                 // 810
    echo "\n";
    
    $date->utcOffset[180];
    
    echo $date->tzName;                      // +03:00
    echo "\n";
    echo $date->utcOffset[];                 // 180
    
    18 vào một biến và sử dụng nó thay vào đó, bởi vì mỗi lệnh gọi thực hiện một lần lặp đầy đủ trong nội bộ

    Để thay đổi các tham số, bạn có thể sử dụng các phương thức setter

    use Carbon\Carbon;
    43

    Bạn có thể thay đổi các tùy chọn bằng cách sử dụng

    $now = Carbon::now[]; // will use timezone as set with date_default_timezone_set
    // PS: we recommend you to work with UTC as default timezone and only use
    // other timezones [such as the user timezone] on display
    
    $nowInLondonTz = Carbon::now[new DateTimeZone['Europe/London']];
    
    // or just pass the timezone as a string
    $nowInLondonTz = Carbon::now['Europe/London'];
    echo $nowInLondonTz->tzName;             // Europe/London
    echo "\n";
    
    // or to create a date with a custom fixed timezone offset
    $date = Carbon::now['+13:30'];
    echo $date->tzName;                      // +13:30
    echo "\n";
    
    // Get/set minutes offset from UTC
    echo $date->utcOffset[];                 // 810
    echo "\n";
    
    $date->utcOffset[180];
    
    echo $date->tzName;                      // +03:00
    echo "\n";
    echo $date->utcOffset[];                 // 180
    
    19 để thay thế tất cả các tùy chọn nhưng bạn cũng có thể thay đổi chúng một cách riêng biệt

    use Carbon\Carbon;
    44

    Bạn có thể kiểm tra xem 2 kỳ có trùng nhau hay không

    use Carbon\Carbon;
    45

    Như đã đề cập trước đó, theo tiêu chuẩn ISO 8601, số lần lặp lại là số lần khoảng thời gian phải được lặp lại. Do đó, DatePeriod gốc sẽ thay đổi số lượng ngày được trả về tùy thuộc vào việc loại trừ ngày bắt đầu. Trong khi đó, CarbonPeriod dễ tha thứ hơn về mặt đầu vào và cho phép các bộ lọc tùy chỉnh, coi các lần lặp lại là giới hạn tổng thể cho số ngày được trả lại

    use Carbon\Carbon;
    46

    Có thể dễ dàng lọc các ngày được trả về bởi DatePeriod. Chẳng hạn, có thể sử dụng các bộ lọc để bỏ qua một số ngày nhất định hoặc chỉ lặp lại trong các ngày làm việc hoặc cuối tuần. Hàm lọc phải trả về

    $dtToronto = Carbon::create[2012, 1, 1, 0, 0, 0, 'America/Toronto'];
    $dtVancouver = Carbon::create[2012, 1, 1, 0, 0, 0, 'America/Vancouver'];
    // Try to replace the 4th number [hours] or the last argument [timezone] with
    // Europe/Paris for example and see the actual result on the right hand.
    // It's alive!
    
    echo $dtVancouver->diffInHours[$dtToronto]; // 3
    // Now, try to double-click on "diffInHours" or "create" to open
    // the References panel.
    // Once the references panel is open, you can use the search field to
    // filter the list or click the [tzName;             // Europe/London
    echo "\n";
    
    // or to create a date with a custom fixed timezone offset
    $date = Carbon::now['+13:30'];
    echo $date->tzName;                      // +13:30
    echo "\n";
    
    // Get/set minutes offset from UTC
    echo $date->utcOffset[];                 // 810
    echo "\n";
    
    $date->utcOffset[180];
    
    echo $date->tzName;                      // +03:00
    echo "\n";
    echo $date->utcOffset[];                 // 180
    
    49 từ các giá trị hỗn hợp bằng cách sử dụng phương pháp
    $mutable = Carbon::now[];
    $immutable = CarbonImmutable::now[];
    $modifiedMutable = $mutable->add[1, 'day'];
    $modifiedImmutable = CarbonImmutable::now[]->add[1, 'day'];
    
    var_dump[$modifiedMutable === $mutable];             // bool[true]
    var_dump[$mutable->isoFormat['dddd D']];             // string[8] "Sunday 1"
    var_dump[$modifiedMutable->isoFormat['dddd D']];     // string[8] "Sunday 1"
    // So it means $mutable and $modifiedMutable are the same object
    // both set to now + 1 day.
    var_dump[$modifiedImmutable === $immutable];         // bool[false]
    var_dump[$immutable->isoFormat['dddd D']];           // string[11] "Saturday 31"
    var_dump[$modifiedImmutable->isoFormat['dddd D']];   // string[8] "Sunday 1"
    // While $immutable is still set to now and cannot be changed and
    // $modifiedImmutable is a new instance created from $immutable
    // set to now + 1 day.
    
    $mutable = CarbonImmutable::now[]->toMutable[];
    var_dump[$mutable->isMutable[]];                     // bool[true]
    var_dump[$mutable->isImmutable[]];                   // bool[false]
    $immutable = Carbon::now[]->toImmutable[];
    var_dump[$immutable->isMutable[]];                   // bool[false]
    var_dump[$immutable->isImmutable[]];                 // bool[true]
    
    09

    use Carbon\Carbon;
    63

    The same way,

    $now = Carbon::now[]; // will use timezone as set with date_default_timezone_set
    // PS: we recommend you to work with UTC as default timezone and only use
    // other timezones [such as the user timezone] on display
    
    $nowInLondonTz = Carbon::now[new DateTimeZone['Europe/London']];
    
    // or just pass the timezone as a string
    $nowInLondonTz = Carbon::now['Europe/London'];
    echo $nowInLondonTz->tzName;             // Europe/London
    echo "\n";
    
    // or to create a date with a custom fixed timezone offset
    $date = Carbon::now['+13:30'];
    echo $date->tzName;                      // +13:30
    echo "\n";
    
    // Get/set minutes offset from UTC
    echo $date->utcOffset[];                 // 810
    echo "\n";
    
    $date->utcOffset[180];
    
    echo $date->tzName;                      // +03:00
    echo "\n";
    echo $date->utcOffset[];                 // 180
    
    53 return
    $dtToronto = Carbon::create[2012, 1, 1, 0, 0, 0, 'America/Toronto'];
    $dtVancouver = Carbon::create[2012, 1, 1, 0, 0, 0, 'America/Vancouver'];
    // Try to replace the 4th number [hours] or the last argument [timezone] with
    // Europe/Paris for example and see the actual result on the right hand.
    // It's alive!
    
    echo $dtVancouver->diffInHours[$dtToronto]; // 3
    // Now, try to double-click on "diffInHours" or "create" to open
    // the References panel.
    // Once the references panel is open, you can use the search field to
    // filter the list or click the [tzName;             // Europe/London
    echo "\n";
    
    // or to create a date with a custom fixed timezone offset
    $date = Carbon::now['+13:30'];
    echo $date->tzName;                      // +13:30
    echo "\n";
    
    // Get/set minutes offset from UTC
    echo $date->utcOffset[];                 // 810
    echo "\n";
    
    $date->utcOffset[180];
    
    echo $date->tzName;                      // +03:00
    echo "\n";
    echo $date->utcOffset[];                 // 180
    
    55 is like
    use Carbon\Carbon;
    83 but throws an exception even if not in strict mode

    Nếu bạn định chuyển từ Carbon 1 sang Carbon 2, vui lòng lưu ý những thay đổi vi phạm sau đây mà bạn nên quan tâm

    Chủ Đề