Converter
Trait Converter.
Change date into different string formats and types and handle the string cast.
Depends on the following methods:
Table of Contents
Methods
- __toString() : string
- Format the instance as a string using the set format
- copy() : void
- 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
- 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
- toFormattedDayDateString() : string
- Format the instance with the day, and a readable date
- toIso8601String() : string
- Format the instance as ISO8601
- toIso8601ZuluString() : string
- Convert the instance to UTC and return as Zulu ISO8601
- toISOString() : string|null
- 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() : string|null
- 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
Methods
__toString()
Format the instance as a string using the set format
public
__toString() : string
Tags
Return values
stringcopy()
public
static copy() : void
format()
Returns the formatted date string on success or FALSE on failure.
public
format(string $format) : string
Parameters
- $format : string
Tags
Return values
stringgetTimeFormatByPrecision()
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
stringrange()
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
CarbonPeriodrawFormat()
public
rawFormat(string $format) : string
Parameters
- $format : string
Tags
Return values
stringtoArray()
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
stringtoCookieString()
Format the instance as COOKIE
public
toCookieString() : string
Tags
Return values
stringtoDate()
public
toDate() : DateTime
Tags
Return values
DateTimetoDateString()
Format the instance as date
public
toDateString() : string
Tags
Return values
stringtoDateTime()
Return native DateTime PHP object matching the current instance.
public
toDateTime() : DateTime
Tags
Return values
DateTimetoDateTimeImmutable()
Return native toDateTimeImmutable PHP object matching the current instance.
public
toDateTimeImmutable() : DateTimeImmutable
Tags
Return values
DateTimeImmutabletoDateTimeLocalString()
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
stringtoDateTimeString()
Format the instance as date and time
public
toDateTimeString([string $unitPrecision = 'second' ]) : string
Parameters
- $unitPrecision : string = 'second'
Tags
Return values
stringtoDayDateTimeString()
Format the instance with day, date and time
public
toDayDateTimeString() : string
Tags
Return values
stringtoFormattedDateString()
Format the instance as a readable date
public
toFormattedDateString() : string
Tags
Return values
stringtoFormattedDayDateString()
Format the instance with the day, and a readable date
public
toFormattedDayDateString() : string
Tags
Return values
stringtoIso8601String()
Format the instance as ISO8601
public
toIso8601String() : string
Tags
Return values
stringtoIso8601ZuluString()
Convert the instance to UTC and return as Zulu ISO8601
public
toIso8601ZuluString([string $unitPrecision = 'second' ]) : string
Parameters
- $unitPrecision : string = 'second'
Tags
Return values
stringtoISOString()
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 ]) : string|null
Parameters
- $keepOffset : bool = false
-
Pass true to keep the date offset. Else forced to UTC.
Tags
Return values
string|nulltoJSON()
Return the ISO-8601 string (ex: 1977-04-22T06:00:00Z) with UTC timezone.
public
toJSON() : string|null
Tags
Return values
string|nulltoObject()
Get default object representation.
public
toObject() : object
Tags
Return values
objecttoPeriod()
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
CarbonPeriodtoRfc1036String()
Format the instance as RFC1036
public
toRfc1036String() : string
Tags
Return values
stringtoRfc1123String()
Format the instance as RFC1123
public
toRfc1123String() : string
Tags
Return values
stringtoRfc2822String()
Format the instance as RFC2822
public
toRfc2822String() : string
Tags
Return values
stringtoRfc3339String()
Format the instance as RFC3339.
public
toRfc3339String([bool $extended = false ]) : string
Parameters
- $extended : bool = false
Tags
Return values
stringtoRfc7231String()
Format the instance as RFC7231
public
toRfc7231String() : string
Tags
Return values
stringtoRfc822String()
Format the instance as RFC822
public
toRfc822String() : string
Tags
Return values
stringtoRfc850String()
Format the instance as RFC850
public
toRfc850String() : string
Tags
Return values
stringtoRssString()
Format the instance as RSS
public
toRssString() : string
Tags
Return values
stringtoString()
Returns english human-readable complete date string.
public
toString() : string
Tags
Return values
stringtoTimeString()
Format the instance as time
public
toTimeString([string $unitPrecision = 'second' ]) : string
Parameters
- $unitPrecision : string = 'second'
Tags
Return values
stringtoW3cString()
Format the instance as W3C
public
toW3cString() : string