Pionia Core

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
example
echo Carbon::now(); // Carbon instances can be cast to string
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

toArray()

Get default array representation.

public toArray() : array<string|int, mixed>
Tags
example
var_dump(Carbon::now()->toArray());
Return values
array<string|int, mixed>

toAtomString()

Format the instance as ATOM

public toAtomString() : string
Tags
example
echo Carbon::now()->toAtomString();
Return values
string

toCookieString()

Format the instance as COOKIE

public toCookieString() : string
Tags
example
echo Carbon::now()->toCookieString();
Return values
string

toDate()

public toDate() : DateTime
Tags
alias

toDateTime

Return native DateTime PHP object matching the current instance.

example
var_dump(Carbon::now()->toDate());
Return values
DateTime

toDateString()

Format the instance as date

public toDateString() : string
Tags
example
echo Carbon::now()->toDateString();
Return values
string

toDateTime()

Return native DateTime PHP object matching the current instance.

public toDateTime() : DateTime
Tags
example
var_dump(Carbon::now()->toDateTime());
Return values
DateTime

toDateTimeImmutable()

Return native toDateTimeImmutable PHP object matching the current instance.

public toDateTimeImmutable() : DateTimeImmutable
Tags
example
var_dump(Carbon::now()->toDateTimeImmutable());
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
example
echo Carbon::now()->toDateTimeLocalString();
echo "\n";
echo Carbon::now()->toDateTimeLocalString('minute'); // You can specify precision among: minute, second, millisecond and microsecond
Return values
string

toDateTimeString()

Format the instance as date and time

public toDateTimeString([string $unitPrecision = 'second' ]) : string
Parameters
$unitPrecision : string = 'second'
Tags
example
echo Carbon::now()->toDateTimeString();
Return values
string

toDayDateTimeString()

Format the instance with day, date and time

public toDayDateTimeString() : string
Tags
example
echo Carbon::now()->toDayDateTimeString();
Return values
string

toFormattedDateString()

Format the instance as a readable date

public toFormattedDateString() : string
Tags
example
echo Carbon::now()->toFormattedDateString();
Return values
string

toFormattedDayDateString()

Format the instance with the day, and a readable date

public toFormattedDayDateString() : string
Tags
example
echo Carbon::now()->toFormattedDayDateString();
Return values
string

toIso8601String()

Format the instance as ISO8601

public toIso8601String() : string
Tags
example
echo Carbon::now()->toIso8601String();
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
example
echo Carbon::now()->toIso8601ZuluString();
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 ]) : string|null
Parameters
$keepOffset : bool = false

Pass true to keep the date offset. Else forced to UTC.

Tags
example
echo Carbon::now('America/Toronto')->toISOString() . "\n";
echo Carbon::now('America/Toronto')->toISOString(true) . "\n";
Return values
string|null

toJSON()

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

public toJSON() : string|null
Tags
example
echo Carbon::now('America/Toronto')->toJSON();
Return values
string|null

toObject()

Get default object representation.

public toObject() : object
Tags
example
var_dump(Carbon::now()->toObject());
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
example
echo Carbon::now()->toRfc1036String();
Return values
string

toRfc1123String()

Format the instance as RFC1123

public toRfc1123String() : string
Tags
example
echo Carbon::now()->toRfc1123String();
Return values
string

toRfc2822String()

Format the instance as RFC2822

public toRfc2822String() : string
Tags
example
echo Carbon::now()->toRfc2822String();
Return values
string

toRfc3339String()

Format the instance as RFC3339.

public toRfc3339String([bool $extended = false ]) : string
Parameters
$extended : bool = false
Tags
example
echo Carbon::now()->toRfc3339String() . "\n";
echo Carbon::now()->toRfc3339String(true) . "\n";
Return values
string

toRfc7231String()

Format the instance as RFC7231

public toRfc7231String() : string
Tags
example
echo Carbon::now()->toRfc7231String();
Return values
string

toRfc822String()

Format the instance as RFC822

public toRfc822String() : string
Tags
example
echo Carbon::now()->toRfc822String();
Return values
string

toRfc850String()

Format the instance as RFC850

public toRfc850String() : string
Tags
example
echo Carbon::now()->toRfc850String();
Return values
string

toRssString()

Format the instance as RSS

public toRssString() : string
Tags
example
echo Carbon::now()->toRssString();
Return values
string

toString()

Returns english human-readable complete date string.

public toString() : string
Tags
example
echo Carbon::now()->toString();
Return values
string

toTimeString()

Format the instance as time

public toTimeString([string $unitPrecision = 'second' ]) : string
Parameters
$unitPrecision : string = 'second'
Tags
example
echo Carbon::now()->toTimeString();
Return values
string

toW3cString()

Format the instance as W3C

public toW3cString() : string
Tags
example
echo Carbon::now()->toW3cString();
Return values
string

        
On this page

Search results