php8.5
Home/ Manual/ intl / intlcalendar/ IntlCalendar::toDateTime

IntlCalendar::toDateTime

PHP function Edit on GitHub ✎

(PHP 5 >= 5.5.0, PHP 7, PHP 8, PECL >= 3.0.0a2)

Convert an IntlCalendar into a DateTime object

Description

Oop

IntlCalendar::toDateTime(): DateTime|false

Procedural

intlcal_to_date_time(IntlCalendar $calendar): DateTime|false

Create a DateTime object that represents the same instant (up to second precision, with a rounding error of less than 1 second) and has an analog timezone to this object (the difference being DateTimeʼs timezone will be backed by PHPʼs timezone while IntlCalendarʼs timezone is backed by ICUʼs).

Parameters

calendar

Intl-calendar

Return Values

A DateTime object with the same timezone as this object (though using PHPʼs database instead of ICUʼs) and the same time, except for the smaller precision (second precision instead of millisecond). Returns false on failure.

Examples

IntlCalendar::toDateTime()

php
<?php
ini_set('date.timezone', 'UTC');
ini_set('intl.default_locale', 'pt_PT');

$cal = IntlCalendar::createInstance('Europe/Lisbon'); //current time

$dt = $cal->toDateTime();
print_r($dt);

The above example will output:

output
DateTime Object
(
    [date] => 2013-07-02 00:29:13
    [timezone_type] => 3
    [timezone] => Europe/Lisbon
)

See Also

  • IntlCalendar::fromDateTime
  • IntlCalendar::getTime
  • IntlCalendar::createInstance
  • DateTime::__construct

Source: reference/intl/intlcalendar/todatetime.xml · from the official PHP manual (php/doc-en)