Phát nổ lần xuất hiện cuối cùng của php

Nếu bạn thực sự yêu thích các cuộc gọi phương thức linh hoạt của mình và cảm thấy thất vọng bởi dòng thừa hoặc cặp dấu ngoặc xấu cần thiết khi sử dụng hàm tạo, bạn sẽ thích phương thức

use Carbon\Carbon;
69

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

Chuỗi được chuyển đến

use Carbon\Carbon;
70 hoặc tới
use Carbon\Carbon;
71 có thể biểu thị thời gian tương đối [chủ nhật tới, ngày mai, ngày đầu tiên của tháng tiếp theo, năm ngoái] hoặc thời gian tuyệt đối [ngày đầu tiên của tháng 12 năm 2008, 2017-01-06]. Bạn có thể kiểm tra xem một chuỗi sẽ tạo ra một ngày tương đối hay tuyệt đối với
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.";
}

Để đi kèm với

use Carbon\Carbon;
68, một số trình trợ giúp khởi tạo tĩnh khác tồn tại để tạo các phiên bản được biết đến rộng rãi. Điều duy nhất cần thực sự chú ý ở đây là
use Carbon\Carbon;
74,
use Carbon\Carbon;
75 và
use Carbon\Carbon;
76, ngoài việc hoạt động như mong đợi, tất cả đều chấp nhận một tham số múi giờ và mỗi giá trị thời gian của chúng được đặt thành
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

Nhóm những người trợ giúp tĩnh tiếp theo là những người trợ giúp

use Carbon\Carbon;
78. Hầu hết các hàm
use Carbon\Carbon;
79 tĩnh cho phép bạn cung cấp nhiều hay ít đối số tùy ý và sẽ cung cấp các giá trị mặc định cho tất cả các đối số khác. Nói chung, các giá trị mặc định là ngày, giờ hoặc múi giờ hiện tại. Các giá trị cao hơn sẽ bao bọc một cách thích hợp nhưng các giá trị không hợp lệ sẽ tạo ra một
use Carbon\Carbon;
80 với một thông báo cung cấp thông tin. Tin nhắn được lấy từ một DateTime. cuộc gọi getLastErrors[]

$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 sẽ mặc định thời gian đến bây giờ.
use Carbon\Carbon;
82 sẽ mặc định ngày là hôm nay.
use Carbon\Carbon;
83 sẽ mặc định bất kỳ tham số null nào về giá trị tương ứng hiện tại. Như trước đây,
use Carbon\Carbon;
84 mặc định là múi giờ hiện tại và nếu không thì có thể là một thể hiện DateTimeZone hoặc đơn giản là một giá trị múi giờ chuỗi. Trường hợp đặc biệt duy nhất dành cho
use Carbon\Carbon;
83 có giá trị tối thiểu làm mặc định cho đối số bị thiếu nhưng mặc định cho giá trị hiện tại khi bạn chuyển rõ ràng
use Carbon\Carbon;
86

use Carbon\Carbon;
0

Tạo ngoại lệ xảy ra trên các giá trị âm như vậy nhưng không xảy ra khi tràn, để có ngoại lệ khi tràn, hãy sử dụng

use Carbon\Carbon;
87

use Carbon\Carbon;
1

lưu ý 1. 2018-02-29 cũng có ngoại lệ trong khi 2020-02-29 thì không vì năm 2020 là năm nhuận

Lưu ý 2.

use Carbon\Carbon;
88 cũng tạo ra một ngoại lệ vì thời gian này là một giờ bị bỏ qua bởi thời gian tiết kiệm ánh sáng ban ngày

lưu ý 3. API gốc PHP cho phép xem xét có một năm

use Carbon\Carbon;
89 giữa
use Carbon\Carbon;
90 và
use Carbon\Carbon;
91 ngay cả khi nó không liên quan đến lịch Gregorian. Đó là lý do tại sao các năm thấp hơn 1 sẽ tạo ra một ngoại lệ bằng cách sử dụng
use Carbon\Carbon;
92. Kiểm tra phát hiện năm-0

use Carbon\Carbon;
2

use Carbon\Carbon;
93 chủ yếu là trình bao bọc cho hàm php cơ sở DateTime. tạoFromFormat. Sự khác biệt một lần nữa là đối số
use Carbon\Carbon;
84 có thể là một thể hiện DateTimeZone hoặc một giá trị múi giờ chuỗi. Ngoài ra, nếu có lỗi với định dạng, chức năng này sẽ gọi phương thức
use Carbon\Carbon;
95 và sau đó đưa ra một
use Carbon\Carbon;
80 với các lỗi dưới dạng thông báo

use Carbon\Carbon;
3

Bạn có thể kiểm tra xem một ngày có khớp với định dạng cho

use Carbon\Carbon;
93 [e. g. thành phần ngày/giờ, từ sửa đổi hoặc dấu tách] bằng cách sử dụng
use Carbon\Carbon;
98 hoặc
use Carbon\Carbon;
99 để đảm bảo dữ liệu thực sự đủ để tạo một phiên bản

use Carbon\Carbon;
4

Bạn có thể tạo các phiên bản từ dấu thời gian unix.

$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 tạo một phiên bản Carbon bằng với dấu thời gian đã cho và cũng sẽ đặt múi giờ hoặc mặc định nó thành múi giờ hiện tạ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]
01, khác ở chỗ múi giờ sẽ vẫn là UTC [GMT+00. 00], nó tương đương 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]
02 nhưng nó hỗ trợ int, float hoặc chuỗi chứa một hoặc nhiều số [như số do
$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 tạo ra] nên nó cũng có thể đặt micro giây mà không bị mất độ chính xác. Thứ ba,
$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, chấp nhận dấu thời gian tính bằng mili giây thay vì giây. Dấu thời gian âm cũng được cho phép

use Carbon\Carbon;
5

Bạn cũng có thể tạo một

$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 của một phiên bản Carbon hiện có. Như mong đợi, tất cả các giá trị ngày, giờ và múi giờ đều được sao chép sang phiên bản mới

use Carbon\Carbon;
6

Bạn có thể sử dụng

$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 trên phiên bản Carbon hiện có để nhận phiên bản mới tại cùng múi giờ

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

Để khắc phục giới hạn này trong Carbon, chúng tôi thêm micro giây khi gọ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]
12 trong PHP < 7. 1, nhưng tính năng này có thể bị tắt theo yêu cầu [không có tác dụng trong 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

Bạn có bao giờ cần lặp lại một số ngày để tìm ngày sớm nhất hoặc mới nhất không?

$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

Giá trị tối thiểu và tối đa chủ yếu phụ thuộc vào hệ thống [32 hoặc 64 bit]

Với hệ điều hành 32-bit hoặc phiên bản 32-bit của PHP [bạn có thể kiểm tra nó bằng PHP 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]
13], giá trị tối thiểu là dấu thời gian 0-unix [1970-01-01 00. 00. 00] và giá trị lớn nhất là dấu thời gian được cung cấp bởi hằng số
$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

Với hệ điều hành 64 bit và phiên bản PHP 64 bit, tối thiểu là 01-01-01 00. 00. 00 và tối đa là 9999-12-31 23. 59. 59. Thậm chí có thể sử dụng năm âm lên đến -9999 nhưng lưu ý rằng bạn có thể không có kết quả chính xác với một số thao tác vì năm 0 tồn tại trong PHP nhưng không có trong lịch Gregorian

Với Carbon 2, quá trình bản địa hóa đã thay đổi rất nhiều, 750 ngôn ngữ mới được hỗ trợ và giờ đây chúng tôi nhúng các định dạng ngôn ngữ, tên ngày, tên tháng, hậu tố thứ tự, kinh tuyến, bắt đầu tuần, v.v. Mặc dù Carbon 1 cung cấp hỗ trợ một phần và dựa vào các gói ngôn ngữ và lớp IntlDateFormatter của bên thứ ba để dịch nâng cao, giờ đây bạn được hưởng lợi từ hỗ trợ quốc tế hóa rộng rãi. Bạn vẫn sử dụng Carbon 1 chứ? . Nếu không, bạn có thể tìm thấy

Thật không may, lớp cơ sở DateTime không có bất kỳ hỗ trợ bản địa hóa nào. Để bắt đầu hỗ trợ bản địa hóa, một 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]
15 đã được thêm vào. Việc triển khai thực hiện cuộc gọi đến strftime bằng cách sử dụng dấu thời gian của phiên bản hiện tại. Nếu lần đầu tiên bạn đặt ngôn ngữ hiện tại bằng hàm PHP setlocale[] thì chuỗi được trả về sẽ được định dạng theo ngôn ngữ chính xác

$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 cũng đã được bản địa hóa. Bạn có thể đặt ngôn ngữ Carbon bằng cách sử dụng hàm tĩnh
$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 và nhận cài đặt hiện tại 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]
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

Hoặc bạn có thể cô lập một số mã với một ngôn ngữ nhất định

$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

Một số ngôn ngữ yêu cầu in mã hóa utf8 [chủ yếu là các gói ngôn ngữ không kết thúc bằng

$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]. Trong trường hợp này, bạn có thể sử dụng phương thức tĩnh
$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 để mã hóa kết quả của lệnh gọi formatLocalized[] thành bộ ký tự utf8

$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

trên Linux
Nếu bạn gặp sự cố với bản dịch, hãy kiểm tra các ngôn ngữ được cài đặt trong hệ thống của bạn [cục bộ và sản xuất]

$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 để liệt kê các ngôn ngữ được bật
$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 để cài đặt ngôn ngữ mớ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]
23 để xuất bản tất cả ngôn ngữ đã bật
Và khởi động lại hệ thống của bạn

kể từ 2. 9. 0, bạn có thể dễ dàng tùy chỉnh bản dịch

$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

Bạn có thể sử dụng ngôn ngữ dự phòng bằng cách chuyển theo thứ tự nhiều ngôn ngữ tớ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]
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

Trong ví dụ trên, nó sẽ cố gắng tìm các bản dịch trong "xx" được ưu tiên, sau đó là "xy" nếu thiếu, sau đó là "es", vì vậy ở đây, bạn nhận được "Xday" từ "xx", "Yday" từ "

Lưu ý rằng bạn cũng có thể sử dụng một trình dịch khác 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]
25 miễn là trình dịch đã cho thực hiệ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]
26. Và bạn có thể nhận trình dịch mặc định chung bằng cách sử dụng
$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 [và
$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 và
$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 cho ngôn ngữ dự phòng, setFallbackLocale có thể được gọi nhiều lần để nhận nhiều ngôn ngữ dự phòng] nhưng vì các phương thức đó sẽ thay đổi hành vi trên toàn cầu [bao gồm cả thư viện của bên thứ ba mà bạn có thể có . Bạn nên tùy chỉnh bản dịch bằng ngôn ngữ tùy chỉnh như trong ví dụ trên

Carbon nhúng trình dịch mặc định mở rộng Symfony\Component\Translation\Translator Bạn có thể

Vì vậy, sự hỗ trợ của một ngôn ngữ 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]
30, các getter như
$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 và các biến thể ngắn được thúc đẩy bởi các ngôn ngữ được cài đặt trong hệ điều hành của bạn. Đối với các bản dịch khác, nó được hỗ trợ nội bộ nhờ cộng đồng Carbon. Bạn có thể kiểm tra những gì được hỗ trợ bằng các phương pháp sau

$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

Vì vậy, đây là cách mới được đề xuất để xử lý quá trình quốc tế hóa với 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

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]
33 chỉ thay đổi ngôn ngữ cho phiên bản hiện tại và được ưu tiên hơn cài đặt chung. Chúng tôi đề xuất cho bạn phương pháp này để bạn không gặp xung đột với những nơi khác hoặc thư viện của bên thứ ba có thể sử dụng Carbon. Tuy nhiên, để tránh gọ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]
33 mỗi lần, bạn có thể sử dụng các nhà má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]
35, đây là cách để nhóm trong một cài đặt cuộc gọi về ngôn ngữ, múi giờ, tràn tháng/năm, v.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 [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 cũng cho phép chuyển các macro cục bộ

$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 hoặc để hợp nhất cài đặt mới với cài đặt hiện có
$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 và lớp để tạo có thể được khởi tạo làm đối số thứ hai của cấu trúc, sau đó được thay đổi sau đó 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]
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 đặt ngôn ngữ trên toàn cầu. Nhưng đối với các trình cài đặt tĩnh khác của chúng tôi, chúng tôi không khuyến khích bạn sử dụng nó. Nó phá vỡ nguyên tắc cô lập vì cấu hình sẽ áp dụng cho mọi lớp sử dụng Carbon

Bạn cũng có thể biết 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]
41 từ Carbon 1. Phương pháp này vẫn hoạt động tương tự trong Carbon 2 nhưng tốt hơn bạn nên sử dụng
$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 để thay thế

$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 sử dụng định dạng ISO thay vì định dạng dành riêng cho PHP và sử dụng các bản dịch bên trong thay vì các gói ngôn ngữ bạn cần cài đặt trên mọi máy mà bạn triển khai ứng dụng của mình. Phương thức
$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 tương thích với phương thức định dạng momentjs, điều đó có nghĩa là bạn có thể sử dụng các chuỗi định dạng giống như bạn có thể đã sử dụng tại thời điểm đó từ giao diện người dùng hoặc nút. js. Dưới đây là một số ví dụ

$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 . 00Bù múi giờ HH. mmZZ+0000Bù múi giờ HHmm

Một số định dạng macro cũng có sẵn. Dưới đây là ví dụ về từng ngôn ngữ

Codeenfrjahr____40_______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 [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
7

ồ. Bạn đã quên min[] và max[]? . Điều đó cũng được bao phủ bởi các phương pháp có tên thích hợp là

$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 [= 0. 5 of the last unit of the diff, this unit will be rounded to the upper value
  • If
    $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 is enabled, the remaining units are summed and if they are > 0 of the last unit of the diff, this unit will be rounded to the upper value
  • If
    $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 is enabled, the last diff unit is rounded down. It makes no difference from the default behavior 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]
    
    16 as the interval can't have overflow, but this option may be needed when used with
    $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 [and unchecked intervals that may have 60 minutes or more, 24 hours or more, etc. ]. For 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".
    
    14 returns
    $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 while
    $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 returns
    $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 [enabled by default]. turns empty diff into 1 second
  • $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 disabled by default]. turns diff from now to now into "just now"
  • $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 calls diffForHumans with options
      $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 [coma-separated],
      $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 [no "ago"/"from now"/"before"/"after" wording],
      $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 [no "just now"/"yesterday"/"tomorrow" wording],
      $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".
      
      40 [no limits] In this mode, you can't change options but you can pass an optional date to compare with or a string + timezone to parse to get this date

    These group of methods perform helpful modifications to the current instance. Most of them are self explanatory from their names. or at least should be. You'll also notice that the startOfXXX[], next[] and previous[] methods set the time to 00. 00. 00 and the endOfXXX[] methods set the time to 23. 59. 59 for unit bigger than days

    The only one slightly different is the

    $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 function. It moves your instance to the middle date between itself and the provided Carbon argument

    The powerful native

    $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 [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 with complementary arguments

    I hear you ask what is a CarbonPeriod instance. Oh. Perfect transition to our next chapter

    CarbonPeriod is a human-friendly version of the DatePeriod with many shortcuts

    use Carbon\Carbon;
    37

    A CarbonPeriod can be constructed in a number of ways

    • start date, end date and optional interval [by default 1 day],
    • ngày bắt đầu, số lần lặp lại và khoảng thời gian tùy chọn,
    • an ISO 8601 interval specification,
    • 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

    Dates can be given as DateTime/Carbon instances, absolute strings like "2007-10-15 15. 00" or relative strings, for example "next monday". Interval can be given as DateInterval/CarbonInterval instance, ISO 8601 interval specification like "P4D", or human readable string, for example "4 days"

    Default constructor and

    use Carbon\Carbon;
    83 methods are very forgiving in terms of argument types and order, so if you want to be more precise the fluent syntax is recommended. On the other hand you can pass dynamic array of values to
    $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 which will do the job of constructing a new instance with the given array as a list of arguments

    CarbonPeriod implements the Iterator interface. It means that it can be passed directly to a

    $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 loop

    use Carbon\Carbon;
    38

    Parameters can be modified during the iteration

    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ả về

    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 [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 giống như
    use Carbon\Carbon;
    83 nhưng đưa ra một ngoại lệ ngay cả khi không ở chế độ nghiêm ngặt

    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ủ Đề