array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'tr', ), 'this' => array ( 0 => 'datetime.settimezone.php', 1 => 'DateTime::setTimezone', 2 => 'Sets the time zone for the DateTime object', ), 'up' => array ( 0 => 'class.datetime.php', 1 => 'DateTime', ), 'prev' => array ( 0 => 'datetime.settimestamp.php', 1 => 'DateTime::setTimestamp', ), 'next' => array ( 0 => 'datetime.sub.php', 1 => 'DateTime::sub', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/datetime/datetime/settimezone.xml', ), 'history' => array ( ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); contributors($setup); ?>

DateTime::setTimezone

date_timezone_set

(PHP 5 >= 5.2.0, PHP 7, PHP 8)

DateTime::setTimezone -- date_timezone_setSets the time zone for the DateTime object

Açıklama

Nesne yönelimli kullanım

public DateTime::setTimezone(DateTimeZone $timezone): DateTime

Yordamsal kullanım

Sets a new timezone for a DateTime object.

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

The procedural version takes the DateTime object as its first argument.

Bağımsız Değişkenler

nesne

Sadece yordamsal tarz: date_create() tarafından bir DateTime nesnesi döndürülür. İşlev bu nesnede değişiklik yapar.

timezone

A DateTimeZone object representing the desired time zone.

Dönen Değerler

Returns the DateTime object for method chaining. The underlaying point-in-time is not changed when calling this method.

Örnekler

Örnek 1 DateTime::setTimeZone() example

Nesne yönelimli kullanım

<?php
$date
= new DateTime('2000-01-01', new DateTimeZone('Pacific/Nauru'));
echo
$date->format('Y-m-d H:i:sP') . "\n";

$date->setTimezone(new DateTimeZone('Pacific/Chatham'));
echo
$date->format('Y-m-d H:i:sP') . "\n";

Yukarıdaki örneğin çıktısı:

2000-01-01 00:00:00+12:00
2000-01-01 01:45:00+13:45

Yordamsal kullanım

<?php
$date
= date_create('2000-01-01', timezone_open('Pacific/Nauru'));
echo
date_format($date, 'Y-m-d H:i:sP') . "\n";

date_timezone_set($date, timezone_open('Pacific/Chatham'));
echo
date_format($date, 'Y-m-d H:i:sP') . "\n";

Yukarıdaki örneğin çıktısı:

2000-01-01 00:00:00+12:00
2000-01-01 01:45:00+13:45

Ayrıca Bakınız