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

search for in the

date_default_timezone_set> <date_date_set
[edit] Last updated: Fri, 17 May 2013

view this page in

date_default_timezone_get

(PHP 5 >= 5.1.0)

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

Açıklama

string date_default_timezone_get ( void )

Bu işlev tercih sırasına göre öntanımlı zaman dilimini şöyle döndürür:

  • date_default_timezone_set() işlevi kullanılarak atanan zaman dilimiyle (eğer varsa).

  • TZ ortam değişkenindeki değerle (boş değilse).

  • date.timezone ini yönergesindeki değerle (ayarlanmışsa).

  • Ev sahibi işletim sistemini sorgulayarak (işletim sistemi destekliyor ve izin veriyorsa).

Eğer yukarıdakilerin hiçbirisi başarılı değilse, date_default_timezone_get() işlevi öntanımlı UTC zaman dilimini döndürecektir.

Dönen Değerler

string türünde geri döner.

Örnekler

Örnek 1 - Öntanımlı zaman diliminin getirilmesi

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

if (
date_default_timezone_get()) {
    echo 
'date_default_timezone_set: 'date_default_timezone_get() .'<br />';
}

if (
ini_get('date.timezone')) {
    echo 
'date.timezone: ' ini_get('date.timezone');
}

?>

Yukarıdaki örnek şuna benzer bir çıktı üretir:

date_default_timezone_set: Europe/Istanbul
date.timezone: Europe/Istanbul

Örnek 2 - Zaman diliminin kısaltmasının getirilmesi

<?php
date_default_timezone_set
('Europe/Istanbul');
echo 
date_default_timezone_get() . ' => ' date('e') . ' => ' date('T');
?>

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

Europe/Istanbul => Europe/Istanbul => EET

Ayrıca Bakınız



date_default_timezone_set> <date_date_set
[edit] Last updated: Fri, 17 May 2013
 
add a note add a note User Contributed Notes date_default_timezone_get - [4 notes]
up
2
glennpratt+php at gmail dot com
2 years ago
In my case, I'm not sure I can guess the correct timezone any better than PHP and it's no where near important enough to nag the user, so...

<?php
// Suppress DateTime warnings
date_default_timezone_set(@date_default_timezone_get());
?>
up
0
Damien dot Garrido dot Work at gmail dot com
10 months ago
To get offset string from offset:

<?php

function timezone_offset_string( $offset )
{
        return
sprintf( "%s%02d:%02d", ( $offset >= 0 ) ? '+' : '-', abs( $offset / 3600 ), abs( $offset % 3600 ) );
}

$offset = timezone_offset_get( new DateTimeZone( 'Pacific/Kiritimati' ), new DateTime() );
echo
"offset: " . timezone_offset_string( $offset ) . "\n";

$offset = timezone_offset_get( new DateTimeZone( 'Pacific/Tahiti' ), new DateTime() );
echo
"offset: " . timezone_offset_string( $offset ) . "\n";
?>

Output:
offset: +14:00
offset: -10:00
up
0
harmor
5 years ago
If you want to get the abbrivation (3 or 4 letter), instead of the long timezone string you can use date('T') function like this:

Input:
date_default_timezone_set('America/Los_Angeles');
echo date_default_timezone_get();
echo ' => '.date('e');
echo ' => '.date('T');

Output:
America/Los_Angeles => America/Los_Angeles => PST
up
0
dohpaz at gmail dot com
6 years ago
date_default_timezone_get() will still emit a warning in E_STRICT if the timezone is not set; either by date_default_timezone_set() or the ini option of date.timezone.

This is probably not a big deal, but I thought I would contribute what I found.

 
show source | credits | stats | sitemap | contact | advertising | mirror sites