DateTimeImmutable::createFromFormat

date_create_immutable_from_format

(PHP 5 >= 5.5.0)

DateTimeImmutable::createFromFormat -- date_create_immutable_from_formatReturns new DateTimeImmutable object formatted according to the specified format

Description

Object oriented style

public static DateTimeImmutable DateTimeImmutable::createFromFormat ( string $format , string $time [, DateTimeZone $timezone ] )

Procedural style

DateTimeImmutable date_create_immutable_from_format ( string $format , string $time [, DateTimeZone $timezone ] )

Like DateTime::createFromFormat() but works with DateTimeImmutable.

Коментарии

Автор:
To clarify, g/G are 12/24 hour time without a leading 0, and h/H are 12/24 hour time with a leading zero, as described here:

https://www.php.net/manual/en/datetime.format.php
2022-11-15 17:24:18
http://php5.kiev.ua/manual/ru/datetimeimmutable.createfromformat.html
If you are not happy with wide range of conversions and repairs this method is making for you, or just want to check that date is really same as input:

```
$datetime = \DateTimeImmutable::createFromFormat('Y-m-d G:i:s', $userDateTimeInput);

if ($datetime && $datetime->format('Y-m-d G:i:s') === $userDateTimeInput) {
  // $datetime is not false and we have a correct date in correct format from user
}
```
2024-01-16 14:20:07
http://php5.kiev.ua/manual/ru/datetimeimmutable.createfromformat.html
Since the description and examples don't exactly match for the timezone row, I want to clarify exactly which format each character outputs.

`e` outputs the timezone identifier, e.g. `America/New_York` or `Asia/Gaza`

`O` outputs the difference to UTC in hours, e.g. `-0500` or `+0200`

`P` outputs difference to UTC with a colon between hours and minutes, e.g. `-05:00` or `+02:00`

`T` outputs the timezone abbreviation, e.g. `EST` or `EET`
2024-01-30 18:08:32
http://php5.kiev.ua/manual/ru/datetimeimmutable.createfromformat.html

    Поддержать сайт на родительском проекте КГБ