Menu

## Converter

Converter.php : 38

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()

Converter.php : 80

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

#### copy()

Converter.php : 0
`public static copy() : void`

#### format()

Converter.php : 47

Returns the formatted date string on success or FALSE on failure.

`public format(string $format) : string`

##### Parameters

$format : string

##### Tags

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

##### Return values

string

#### getTimeFormatByPrecision()

Converter.php : 165

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()

Converter.php : 550

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()

Converter.php : 67
`public rawFormat(string $format) : string`

##### Parameters

$format : string

##### Tags

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

##### Return values

string

#### toArray()

Converter.php : 386

Get default array representation.

`public toArray() : array<string|int, mixed>`

##### Tags

example

      var_dump(Carbon::now()->toArray());

##### Return values

array<string|int, mixed>

#### toAtomString()

Converter.php : 212

Format the instance as ATOM

`public toAtomString() : string`

##### Tags

example

      echo Carbon::now()->toAtomString();

##### Return values

string

#### toCookieString()

Converter.php : 225

Format the instance as COOKIE

`public toCookieString() : string`

##### Tags

example

      echo Carbon::now()->toCookieString();

##### Return values

string

#### toDate()

Converter.php : 504
`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()

Converter.php : 103

Format the instance as date

`public toDateString() : string`

##### Tags

example

      echo Carbon::now()->toDateString();

##### Return values

string

#### toDateTime()

Converter.php : 476

Return native DateTime PHP object matching the current instance.

`public toDateTime() : DateTime`

##### Tags

example

      var_dump(Carbon::now()->toDateTime());

##### Return values

DateTime

#### toDateTimeImmutable()

Converter.php : 489

Return native toDateTimeImmutable PHP object matching the current instance.

`public toDateTimeImmutable() : DateTimeImmutable`

##### Tags

example

      var_dump(Carbon::now()->toDateTimeImmutable());

##### Return values

DateTimeImmutable

#### toDateTimeLocalString()

Converter.php : 186

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()

Converter.php : 155

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()

Converter.php : 199

Format the instance with day, date and time

`public toDayDateTimeString() : string`

##### Tags

example

      echo Carbon::now()->toDayDateTimeString();

##### Return values

string

#### toFormattedDateString()

Converter.php : 116

Format the instance as a readable date

`public toFormattedDateString() : string`

##### Tags

example

      echo Carbon::now()->toFormattedDateString();

##### Return values

string

#### toFormattedDayDateString()

Converter.php : 129

Format the instance with the day, and a readable date

`public toFormattedDayDateString() : string`

##### Tags

example

      echo Carbon::now()->toFormattedDayDateString();

##### Return values

string

#### toIso8601String()

Converter.php : 238

Format the instance as ISO8601

`public toIso8601String() : string`

##### Tags

example

      echo Carbon::now()->toIso8601String();

##### Return values

string

#### toIso8601ZuluString()

Converter.php : 264

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()

Converter.php : 442

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()

Converter.php : 463

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()

Converter.php : 412

Get default object representation.

`public toObject() : object`

##### Tags

example

      var_dump(Carbon::now()->toObject());

##### Return values

object

#### toPeriod()

Converter.php : 516

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()

Converter.php : 292

Format the instance as RFC1036

`public toRfc1036String() : string`

##### Tags

example

      echo Carbon::now()->toRfc1036String();

##### Return values

string

#### toRfc1123String()

Converter.php : 305

Format the instance as RFC1123

`public toRfc1123String() : string`

##### Tags

example

      echo Carbon::now()->toRfc1123String();

##### Return values

string

#### toRfc2822String()

Converter.php : 318

Format the instance as RFC2822

`public toRfc2822String() : string`

##### Tags

example

      echo Carbon::now()->toRfc2822String();

##### Return values

string

#### toRfc3339String()

Converter.php : 332

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()

Converter.php : 371

Format the instance as RFC7231

`public toRfc7231String() : string`

##### Tags

example

      echo Carbon::now()->toRfc7231String();

##### Return values

string

#### toRfc822String()

Converter.php : 251

Format the instance as RFC822

`public toRfc822String() : string`

##### Tags

example

      echo Carbon::now()->toRfc822String();

##### Return values

string

#### toRfc850String()

Converter.php : 279

Format the instance as RFC850

`public toRfc850String() : string`

##### Tags

example

      echo Carbon::now()->toRfc850String();

##### Return values

string

#### toRssString()

Converter.php : 345

Format the instance as RSS

`public toRssString() : string`

##### Tags

example

      echo Carbon::now()->toRssString();

##### Return values

string

#### toString()

Converter.php : 425

Returns english human-readable complete date string.

`public toString() : string`

##### Tags

example

      echo Carbon::now()->toString();

##### Return values

string

#### toTimeString()

Converter.php : 142

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()

Converter.php : 358

Format the instance as W3C

`public toW3cString() : string`

##### Tags

example

      echo Carbon::now()->toW3cString();

##### Return values

string

## Search results