downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

date_diff> <date_default_timezone_get
Last updated: Fri, 27 Nov 2009

view this page in

date_default_timezone_set

(PHP 5 >= 5.1.0)

date_default_timezone_set Betik içerisindeki tüm tarih/zaman işlevleri tarafından kullanılan öntanımlı zaman dilimini ayarlar

Açıklama

bool date_default_timezone_set ( string $zamandilimi_belirteci )

date_default_timezone_set() işlevi, tüm tarih/zaman işlevleri tarafından kullanılan öntanımlı zaman dilimini ayarlar.

Bilginize: PHP 5.1.0 sürümünden beri (tarih/zaman işlevleri yeniden yazıldığından beri), bir tarih/zaman işlevinin her çağrılışında, eğer zaman dilimi geçerli değilse bir E_NOTICE, eğer sistem ayarları ya da TZ ortam değişkeni kullanılıyorsa bir E_WARNING iletisi üretilmektedir.

Öntanımlı zaman dilimini ayarlamak için, bu işlevi betiğinizde kullanmak yerine, INI ayarlarındaki date.timezone yönergesini de kullanabilirsiniz.

Değiştirgeler

zamandilimi_belirteci

Zaman dilimi belirteci, UTC ya da Europe/Istanbul gibi bir değer olabilir. Geçerli belirteçlerin listesi Desteklenen Zaman Dilimlerinin Listesi bölümünde bulunmaktadır.

Dönen Değerler

Bu işlev zamandilimi_belirteci geçersizse FALSE, aksi takdirde TRUE döndürür.

Örnekler

Örnek 1 - Öntanımlı zaman dilimini almak

<?php
date_default_timezone_set
('Europa/Istanbul');

$betik_zd date_default_timezone_get();

if (
strcmp($betik_zdini_get('date.timezone'))){
    echo 
'Betik zaman dilimi ini dosyasında belirtilenden farklı.';
} else {
    echo 
'Betik zaman dilimi ini dosyasında belirtilenle aynı.';
}
?>

Sürüm Bilgisi

Sürüm: Açıklama
5.3.0 Artık E_STRICT yerine E_WARNING oluşuyor.
5.1.2 İşlev, zamandilimi_belirteci değiştirgesini kullanmaya başladı.

Ayrıca Bakınız



date_diff> <date_default_timezone_get
Last updated: Fri, 27 Nov 2009
 
add a note add a note User Contributed Notes
date_default_timezone_set
ted dot chou12 at gmail dot com
03-Dec-2008 07:13
Timezone using other approaches:
<?php $datetime = strtotime($originaldatetime) + $time;
$datetime = date('M d, Y h:i A', $datetime);?>

$time obtained from table below:
-25200|International Date Line (West) GMT-12|
-21600|Midway Island, Samoa GMT-11|
-18000|Hawaii, Honolulu GMT-10|
-14400|Alaska GMT-9|
-10800|Pacific Standard Time, US, Canada GMT-8|
-7200|British Columbia N.E., Santa Fe, Mountain Time GMT-7|
-3600|Central America, Chicago, Guatamala, Mexico City GMT-6|
0|US, Canada, Bogota, Boston, New York GMT-5|
+3600|Canada, Santiago, Atlantic Standard Time GMT-4|
+7200|Brazilia, Buenos Aires, Georgetown, Greenland GMT-3|
+10800|Mid-Atlantic GMT-2|
+14400|Azores, Cape Verde Is., Western Africa Time GMT-1|
+18000|London, Iceland, Ireland, Morocco, Portugal GMT|
+21600|Amsterdam, Berlin, Bern, Madrid, Paris, Rome, GMT+1|
+25200|Athens, Cairo, Cape Town, Finland, Greece, Israel GMT+2|
+28800|Ankara, Aden, Baghdad, Beruit, Kuwait, Moscow GMT+3|
+32400|Abu Dhabi, Baku, Kabul, Tehran, Tbilisi, Volgograd GMT+4|
+36000|Calcutta, Colombo, Islamabad, Madras, New Dehli GMT+5|
+39600|Almaty, Dhakar, Kathmandu, Colombo, Sri Lanka GMT+6|
+43200|Bangkok, Hanoi, Jakarta, Phnom Penh, Australia GMT+7|
+46800|Taipei, Beijing, Hong Kong, Singapore, GMT+8|
+50400|Seoul, Tokyo, Central Australia GMT+9|
+54000|Brisbane, Canberra, Guam, Melbourne, Sydney, GMT+10|
+57600|Magadan, New Caledonia, Solomon Is. GMT+11|
+61200|Auckland, Fiji, Kamchatka, Marshall, Wellington, GMT+12|
jason at jasonpriem dot com
12-Nov-2008 04:29
While it's easy to change timezones based on names or abbreviations, I haven't found any straightforward way of doing so using an offset integer.  This situation comes up if you're using AJAX to get information about a user's timezone; javascript's getTimezoneOffset() method just sends you an offset number. So, here's my clunky solution: an adaptation of chris' function at http://us.php.net/manual/en/function.timezone-name-from-abbr.php.

<?php
   
function set_tz_by_offset($offset) {
       
$abbrarray = timezone_abbreviations_list();
        foreach (
$abbrarray as $abbr) {
                foreach (
$abbr as $city) {
                        if (
$city['offset'] == $offset) { // remember to multiply $offset by -1 if you're getting it from js
                              
date_default_timezone_set($city['timezone_id']);
                               return
true;
                        }
                }
        }
   
date_default_timezone_set("ust");
       return
false;
       }
?>
Anonymous
28-Sep-2008 05:34
If you have problems with errors, why the default is not set use this on the top of the script:

<?php
if(function_exists("date_default_timezone_set") and function_exists("date_default_timezone_get"))
@
date_default_timezone_set(@date_default_timezone_get());
?>
Rob Kaper
15-Jul-2008 08:46
If you want users to choose their own timezones, here's some code that gets all available timezones but only uses one city for each possible value:

<?php

$timezones
= DateTimeZone::listAbbreviations();

$cities = array();
foreach(
$timezones as $key => $zones )
{
    foreach(
$zones as $id => $zone )
    {
       
/**
         * Only get timezones explicitely not part of "Others".
         * @see http://www.php.net/manual/en/timezones.others.php
         */
       
if ( preg_match( '/^(America|Antartica|Arctic|Asia|Atlantic|Europe|Indian|Pacific)\//', $zone['timezone_id'] ) )
           
$cities[$zone['timezone_id']][] = $key;
    }
}

// For each city, have a comma separated list of all possible timezones for that city.
foreach( $cities as $key => $value )
   
$cities[$key] = join( ', ', $value);

// Only keep one city (the first and also most important) for each set of possibilities.
$cities = array_unique( $cities );

// Sort by area/city name.
ksort( $cities );

?>
PeerGoal.com
12-Feb-2007 12: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 01: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.

[red. That is only true for the putenv() hack - Derick]

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.

date_diff> <date_default_timezone_get
Last updated: Fri, 27 Nov 2009
 
 
show source | credits | sitemap | contact | advertising | mirror sites