suche nach in der

date_diff> <date_default_timezone_get
Last updated: Fri, 18 May 2012

view this page in

date_default_timezone_set

(PHP 5 >= 5.1.0)

date_default_timezone_set Sets the default timezone used by all date/time functions in a script

Beschreibung

bool date_default_timezone_set ( string $timezone_identifier )

date_default_timezone_set() sets the default timezone used by all date/time functions.

Hinweis:

Since PHP 5.1.0 (when the date/time functions were rewritten), every call to a date/time function will generate a E_NOTICE if the timezone isn't valid, and/or a E_WARNING message if using the system settings or the TZ environment variable.

Instead of using this function to set the default timezone in your script, you can also use the INI setting date.timezone to set the default timezone.

Parameter-Liste

timezone_identifier

The timezone identifier, like UTC or Europe/Lisbon. The list of valid identifiers is available in the Liste unterstützter Zeitzonen.

Rückgabewerte

This function returns FALSE if the timezone_identifier isn't valid, or TRUE otherwise.

Beispiele

Beispiel #1 Getting the default timezone

<?php
date_default_timezone_set
('America/Los_Angeles');

$script_tz date_default_timezone_get();

if (
strcmp($script_tzini_get('date.timezone'))){
    echo 
'Script timezone differs from ini-set timezone.';
} else {
    echo 
'Script timezone and ini-set timezone match.';
}
?>

Changelog

Version Beschreibung
5.3.0 Now throws E_WARNING rather than E_STRICT.
5.1.2 The function started to validate the timezone_identifier parameter.

Siehe auch



add a note add a note User Contributed Notes
date_default_timezone_set
legolas558 d0t users dot sf dot net
10-Jun-2007 03:34
http://drakecms.sf.net/index.php?option=content&id=32&Itemid=10

A short tutorial which explains how to consistently implement timezones with PHP4 while remaining forward compatible with PHP5.
PeerGoal.com
12-Feb-2007 01:21
The problem:

date() [function.date]: It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Los_Angeles' for 'PST/-8.0/no DST' instead

Of course this is a problem that recently surfaced since PHP5. Quick fix is to set your time zone, add this line to your php code:

date_default_timezone_set("America/Los_Angeles");
davidn at datalinktech dot com dot au
22-Dec-2006 02:27
Note that there may be some unexpected side-effects that result from using either set_default_timezone() or the putenv("TZ=...") workalike for earlier PHP versions.  ANY date formatted and output either by PHP or its apache host process will be unconditionally expressed in that timezone.

This does indeed include the web server's logs and other output files and reports which by default usually do not include any indication of timezone. This has a further side-effect on log processing and analysis, obviously.
Chris
23-Nov-2006 07:14
See the user contributed notes for the putenv function for a workaround for previous versions of PHP.

date_diff> <date_default_timezone_get
Last updated: Fri, 18 May 2012