trait Converter

Trait Converter.

Change date into different string formats and types and handle the string cast.

Depends on the following methods:

Properties

staticprotectedstring|Closure|null $toStringFormat Format to use for __toString method when type juggling occurs.

Methods

static void
resetToStringFormat()

Reset the format used to the default when type juggling a Carbon instance to a string

static void
setToStringFormat(string|Closure|null$format)deprecated

No description

format($format)

No description

string
rawFormat(string$format)

No description

string
__toString()

Format the instance as a string using the set format

string
toDateString()

Format the instance as date

string
toFormattedDateString()

Format the instance as a readable date

string
toFormattedDayDateString()

Format the instance with the day, and a readable date

string
toTimeString(string$unitPrecision ='second')

Format the instance as time

string
toDateTimeString(string$unitPrecision ='second')

Format the instance as date and time

static string
getTimeFormatByPrecision(string$unitPrecision)

Return a format from H:i to H:i:s.u according to given unit precision.

string
toDateTimeLocalString(string$unitPrecision ='second')

Format the instance as date and time T-separated with no timezone

string
toDayDateTimeString()

Format the instance with day, date and time

string
toAtomString()

Format the instance as ATOM

string
toCookieString()

Format the instance as COOKIE

string
toIso8601String()

Format the instance as ISO8601

string
toRfc822String()

Format the instance as RFC822

string
toIso8601ZuluString(string$unitPrecision ='second')

Convert the instance to UTC and return as Zulu ISO8601

string
toRfc850String()

Format the instance as RFC850

string
toRfc1036String()

Format the instance as RFC1036

string
toRfc1123String()

Format the instance as RFC1123

string
toRfc2822String()

Format the instance as RFC2822

string
toRfc3339String(bool$extended =false)

Format the instance as RFC3339

string
toRssString()

Format the instance as RSS

string
toW3cString()

Format the instance as W3C

string
toRfc7231String()

Format the instance as RFC7231

array
toArray()

Get default array representation.

object
toObject()

Get default object representation.

string
toString()

Returns english human readable complete date string.

null|string
toISOString(bool$keepOffset =false)

Return the ISO-8601 string (ex: 1977-04-22T06:00:00Z, if $keepOffset truthy, offset will be kept: 1977-04-22T01:00:00-05:00).

null|string
toJSON()

Return the ISO-8601 string (ex: 1977-04-22T06:00:00Z) with UTC timezone.

toDateTime()

Return native DateTime PHP object matching the current instance.

toDateTimeImmutable()

Return native toDateTimeImmutable PHP object matching the current instance.

toDate()

No description

toPeriod(DateTimeInterface|Carbon|CarbonImmutable|int|null$end =null,int|DateInterval|string|null$interval =null,string|null$unit =null)

Create a iterable CarbonPeriod object from current date to a given end date (and optional interval).

range(DateTimeInterface|Carbon|CarbonImmutable|null$end =null,int|DateInterval|string|null$interval =null,string|null$unit =null)

Create a iterable CarbonPeriod object from current date to a given end date (and optional interval).

static
copy()

No description

Details

at line49
staticvoid resetToStringFormat()

Reset the format used to the default when type juggling a Carbon instance to a string

Return Value

void

at line66
staticvoid setToStringFormat(string|Closure|null$format)deprecated

deprecated To avoid conflict between different third-party libraries, static setters should not be used. You should rather let Carbon object being casted to string with DEFAULT_TO_STRING_FORMAT, and use other method or custom format passed to format() method if you need to dump an other string format. Set the default format used when type juggling a Carbon instance to a string

Parameters

string|Closure|null $format

Return Value

void

at line81
format($format)

Parameters

$format

at line103
string rawFormat(string$format)

Parameters

string $format

Return Value

string

See also

https://php.net/manual/en/datetime.format.php

at line118
string __toString()

Format the instance as a string using the set format

Return Value

string

at line141
string toDateString()

Format the instance as date

Return Value

string

at line156
string toFormattedDateString()

Format the instance as a readable date

Return Value

string

at line171
string toFormattedDayDateString()

Format the instance with the day, and a readable date

Return Value

string

at line188
string toTimeString(string$unitPrecision ='second')

Format the instance as time

Parameters

string $unitPrecision

Return Value

string

at line205
string toDateTimeString(string$unitPrecision ='second')

Format the instance as date and time

Parameters

string $unitPrecision

Return Value

string

at line217
staticstring getTimeFormatByPrecision(string$unitPrecision)

Return a format from H:i to H:i:s.u according to given unit precision.

Parameters

string $unitPrecision "minute", "second", "millisecond" or "microsecond"

Return Value

string

at line249
string toDateTimeLocalString(string$unitPrecision ='second')

Format the instance as date and time T-separated with no timezone

Parameters

string $unitPrecision

Return Value

string

at line264
string toDayDateTimeString()

Format the instance with day, date and time

Return Value

string

at line279
string toAtomString()

Format the instance as ATOM

Return Value

string

at line294
string toCookieString()

Format the instance as COOKIE

Return Value

string

at line309
string toIso8601String()

Format the instance as ISO8601

Return Value

string

at line324
string toRfc822String()

Format the instance as RFC822

Return Value

string

at line341
string toIso8601ZuluString(string$unitPrecision ='second')

Convert the instance to UTC and return as Zulu ISO8601

Parameters

string $unitPrecision

Return Value

string

at line358
string toRfc850String()

Format the instance as RFC850

Return Value

string

at line373
string toRfc1036String()

Format the instance as RFC1036

Return Value

string

at line388
string toRfc1123String()

Format the instance as RFC1123

Return Value

string

at line403
string toRfc2822String()

Format the instance as RFC2822

Return Value

string

at line421
string toRfc3339String(bool$extended =false)

Format the instance as RFC3339

Parameters

bool $extended

Return Value

string

at line441
string toRssString()

Format the instance as RSS

Return Value

string

at line456
string toW3cString()

Format the instance as W3C

Return Value

string

at line471
string toRfc7231String()

Format the instance as RFC7231

Return Value

string

at line488
array toArray()

Get default array representation.

Return Value

array

at line516
object toObject()

Get default object representation.

Return Value

object

at line531
string toString()

Returns english human readable complete date string.

Return Value

string

at line550
null|string toISOString(bool$keepOffset =false)

Return the ISO-8601 string (ex: 1977-04-22T06:00:00Z, if $keepOffset truthy, offset will be kept: 1977-04-22T01:00:00-05:00).

Parameters

bool $keepOffset Pass true to keep the date offset. Else forced to UTC.

Return Value

null|string

at line573
null|string toJSON()

Return the ISO-8601 string (ex: 1977-04-22T06:00:00Z) with UTC timezone.

Return Value

null|string

at line588
DateTime toDateTime()

Return native DateTime PHP object matching the current instance.

Return Value

DateTime

at line603
DateTimeImmutable toDateTimeImmutable()

Return native toDateTimeImmutable PHP object matching the current instance.

Return Value

DateTimeImmutable

at line620
DateTime toDate()

Return Value

DateTime

at line634
CarbonPeriod toPeriod(DateTimeInterface|Carbon|CarbonImmutable|int|null$end =null,int|DateInterval|string|null$interval =null,string|null$unit =null)

Create a iterable CarbonPeriod object from current date to a given end date (and optional interval).

Parameters

DateTimeInterface|Carbon|CarbonImmutable|int|null $end period end date or recurrences count if int
int|DateInterval|string|null $interval period default interval or number of the given $unit
string|null $unit if specified, $interval must be an integer

Return Value

CarbonPeriod

at line664
CarbonPeriod range(DateTimeInterface|Carbon|CarbonImmutable|null$end =null,int|DateInterval|string|null$interval =null,string|null$unit =null)

Create a iterable CarbonPeriod object from current date to a given end date (and optional interval).

Parameters

DateTimeInterface|Carbon|CarbonImmutable|null $end period end date
int|DateInterval|string|null $interval period default interval or number of the given $unit
string|null $unit if specified, $interval must be an integer

Return Value

CarbonPeriod

at line35
static copy()

Return Value

static