Converter
Trait Converter.
Change date into different string formats and types and handle the string cast.
Depends on the following methods:
Table of Contents
- $toStringFormat : string|Closure|null
- Format to use for __toString method when type juggling occurs.
- __toString() : string
- Format the instance as a string using the set format
- copy() : Carbon|CarbonImmutable
- format() : string
- Returns the formatted date string on success or FALSE on failure.
- getTimeFormatByPrecision() : string
- Return a format from H:i to H:i:s.u according to given unit precision.
- range() : CarbonPeriod
- Create a iterable CarbonPeriod object from current date to a given end date (and optional interval).
- rawFormat() : string
- resetToStringFormat() : void
- Reset the format used to the default when type juggling a Carbon instance to a string
- setToStringFormat() : void
- toArray() : array<string|int, mixed>
- Get default array representation.
- toAtomString() : string
- Format the instance as ATOM
- toCookieString() : string
- Format the instance as COOKIE
- toDate() : DateTime
- toDateString() : string
- Format the instance as date
- toDateTime() : DateTime
- Return native DateTime PHP object matching the current instance.
- toDateTimeImmutable() : DateTimeImmutable
- Return native toDateTimeImmutable PHP object matching the current instance.
- toDateTimeLocalString() : string
- Format the instance as date and time T-separated with no timezone
- toDateTimeString() : string
- Format the instance as date and time
- toDayDateTimeString() : string
- Format the instance with day, date and time
- toFormattedDateString() : string
- Format the instance as a readable date
- toIso8601String() : string
- Format the instance as ISO8601
- toIso8601ZuluString() : string
- Convert the instance to UTC and return as Zulu ISO8601
- toISOString() : null|string
- 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).
- toJSON() : null|string
- Return the ISO-8601 string (ex: 1977-04-22T06:00:00Z) with UTC timezone.
- toObject() : object
- Get default object representation.
- toPeriod() : CarbonPeriod
- Create a iterable CarbonPeriod object from current date to a given end date (and optional interval).
- toRfc1036String() : string
- Format the instance as RFC1036
- toRfc1123String() : string
- Format the instance as RFC1123
- toRfc2822String() : string
- Format the instance as RFC2822
- toRfc3339String() : string
- Format the instance as RFC3339
- toRfc7231String() : string
- Format the instance as RFC7231
- toRfc822String() : string
- Format the instance as RFC822
- toRfc850String() : string
- Format the instance as RFC850
- toRssString() : string
- Format the instance as RSS
- toString() : string
- Returns english human readable complete date string.
- toTimeString() : string
- Format the instance as time
- toW3cString() : string
- Format the instance as W3C
Properties
$toStringFormat
Format to use for __toString method when type juggling occurs.
protected
static string|Closure|null
$toStringFormat
= null
Methods
__toString()
Format the instance as a string using the set format
public
__toString() : string
Tags
Return values
string —copy()
public
copy() : Carbon|CarbonImmutable
Return values
Carbon|CarbonImmutable —format()
Returns the formatted date string on success or FALSE on failure.
public
format(string $format) : string
Parameters
- $format : string
Tags
Return values
string —getTimeFormatByPrecision()
Return a format from H:i to H:i:s.u according to given unit precision.
public
static getTimeFormatByPrecision(string $unitPrecision) : string
Parameters
- $unitPrecision : string
-
"minute", "second", "millisecond" or "microsecond"
Return values
string —range()
Create a iterable CarbonPeriod object from current date to a given end date (and optional interval).
public
range([DateTimeInterface|Carbon|CarbonImmutable|null $end = null ][, int|DateInterval|string|null $interval = null ][, string|null $unit = null ]) : CarbonPeriod
Parameters
- $end : DateTimeInterface|Carbon|CarbonImmutable|null = null
-
period end date
- $interval : int|DateInterval|string|null = null
-
period default interval or number of the given $unit
- $unit : string|null = null
-
if specified, $interval must be an integer
Return values
CarbonPeriod —rawFormat()
public
rawFormat(string $format) : string
Parameters
- $format : string
Tags
Return values
string —resetToStringFormat()
Reset the format used to the default when type juggling a Carbon instance to a string
public
static resetToStringFormat() : void
Return values
void —setToStringFormat()
public
static setToStringFormat(string|Closure|null $format) : void
Parameters
- $format : string|Closure|null
Tags
Return values
void —toArray()
Get default array representation.
public
toArray() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —toAtomString()
Format the instance as ATOM
public
toAtomString() : string
Tags
Return values
string —toCookieString()
Format the instance as COOKIE
public
toCookieString() : string
Tags
Return values
string —toDate()
public
toDate() : DateTime
Tags
Return values
DateTime —toDateString()
Format the instance as date
public
toDateString() : string
Tags
Return values
string —toDateTime()
Return native DateTime PHP object matching the current instance.
public
toDateTime() : DateTime
Tags
Return values
DateTime —toDateTimeImmutable()
Return native toDateTimeImmutable PHP object matching the current instance.
public
toDateTimeImmutable() : DateTimeImmutable
Tags
Return values
DateTimeImmutable —toDateTimeLocalString()
Format the instance as date and time T-separated with no timezone
public
toDateTimeLocalString([string $unitPrecision = 'second' ]) : string
Parameters
- $unitPrecision : string = 'second'
Tags
Return values
string —toDateTimeString()
Format the instance as date and time
public
toDateTimeString([string $unitPrecision = 'second' ]) : string
Parameters
- $unitPrecision : string = 'second'
Tags
Return values
string —toDayDateTimeString()
Format the instance with day, date and time
public
toDayDateTimeString() : string
Tags
Return values
string —toFormattedDateString()
Format the instance as a readable date
public
toFormattedDateString() : string
Tags
Return values
string —toIso8601String()
Format the instance as ISO8601
public
toIso8601String() : string
Tags
Return values
string —toIso8601ZuluString()
Convert the instance to UTC and return as Zulu ISO8601
public
toIso8601ZuluString([string $unitPrecision = 'second' ]) : string
Parameters
- $unitPrecision : string = 'second'
Tags
Return values
string —toISOString()
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).
public
toISOString([bool $keepOffset = false ]) : null|string
Parameters
- $keepOffset : bool = false
-
Pass true to keep the date offset. Else forced to UTC.
Tags
Return values
null|string —toJSON()
Return the ISO-8601 string (ex: 1977-04-22T06:00:00Z) with UTC timezone.
public
toJSON() : null|string
Tags
Return values
null|string —toObject()
Get default object representation.
public
toObject() : object
Tags
Return values
object —toPeriod()
Create a iterable CarbonPeriod object from current date to a given end date (and optional interval).
public
toPeriod([DateTimeInterface|Carbon|CarbonImmutable|int|null $end = null ][, int|DateInterval|string|null $interval = null ][, string|null $unit = null ]) : CarbonPeriod
Parameters
- $end : DateTimeInterface|Carbon|CarbonImmutable|int|null = null
-
period end date or recurrences count if int
- $interval : int|DateInterval|string|null = null
-
period default interval or number of the given $unit
- $unit : string|null = null
-
if specified, $interval must be an integer
Return values
CarbonPeriod —toRfc1036String()
Format the instance as RFC1036
public
toRfc1036String() : string
Tags
Return values
string —toRfc1123String()
Format the instance as RFC1123
public
toRfc1123String() : string
Tags
Return values
string —toRfc2822String()
Format the instance as RFC2822
public
toRfc2822String() : string
Tags
Return values
string —toRfc3339String()
Format the instance as RFC3339
public
toRfc3339String() : string
Tags
Return values
string —toRfc7231String()
Format the instance as RFC7231
public
toRfc7231String() : string
Tags
Return values
string —toRfc822String()
Format the instance as RFC822
public
toRfc822String() : string
Tags
Return values
string —toRfc850String()
Format the instance as RFC850
public
toRfc850String() : string
Tags
Return values
string —toRssString()
Format the instance as RSS
public
toRssString() : string
Tags
Return values
string —toString()
Returns english human readable complete date string.
public
toString() : string
Tags
Return values
string —toTimeString()
Format the instance as time
public
toTimeString([string $unitPrecision = 'second' ]) : string
Parameters
- $unitPrecision : string = 'second'
Tags
Return values
string —toW3cString()
Format the instance as W3C
public
toW3cString() : string