DateTime
PHP 手册

DateTime::setTimezone

(PHP 5 >= 5.2.0)

DateTime::setTimezoneSets the time zone for the DateTime object

说明

public DateTime DateTime::setTimezone ( DateTimeZone $timezone )

参数

object

Procedural style only: A DateTime object returned by date_create()

timezone

Desired time zone.

返回值

Returns the modified DateTime.

范例

Example #1 Setting and getting DateTimeZone objects

<?php
date_default_timezone_set
('Europe/London');

$datetime = new DateTime('2008-08-03 12:35:23');
echo 
$datetime->getTimezone()->getName() . "\n";

$datetime = new DateTime('2008-08-03 12:35:23');
$la_time = new DateTimeZone('America/Los_Angeles');
$datetime->setTimezone($la_time);
echo 
$datetime->getTimezone()->getName();
?>

上例将输出:

Europe/London
America/Los_Angeles

参见


DateTime
PHP 手册