PHP Velho Oeste 2024

getdate

(PHP 4, PHP 5, PHP 7, PHP 8)

getdateTarih/zaman bilgisi getirir

Açıklama

getdate(?int $zaman_damgası = null): array

Bağımsız değişkenle çağrılmışsa zaman_damgası'na karşılık olan tarih bilgisini bir ilişkisel dizi olarak döndürür. Bağımsız değişkensiz çağrılmışsa dönen değer o anın yerel zamanına göre olur.

Bağımsız Değişkenler

zaman_damgası

Seçimlik zaman_damgası bağımsız değişkeni int türünde bir Unix zaman damgası olup belirtilmediği takdirde veya null ise yerel zaman kullanılır. Başka bir deyişle, time() işlevinden dönen değer öntanımlıdır.

Dönen Değerler

zaman_damgası'na karşılık olan tarih bilgisini bir ilişkisel dizi olarak döndürür. İlişkisel dizide döndürülen öğeler aşağıdaki gibidir:

İlişkisel diziyle döndürülen anahtarlar
Anahtar Açıklama Örnek dönüş değerleri
"seconds" Saniyelerin sayısal gösterimi 0'dan 59'a kadar
"minutes" Dakikaların sayısal gösterimi 0'dan 59'a kadar
"hours" Saatlerin sayılsal gösterimi 0'dan 23'e kadar
"mday" Ayın günlerinin sayısal gösterimi 1'den 31'e kadar
"wday" Haftanın günlerinin sayılsal gösterimi (Pazar için) 0'dan (Cumartesi için) 6'ya kadar
"mon" Ayın sayısal gösterimi 1 'den 12'ye kadar
"year" Yılın 4 haneli sayısal tam gösterimi Örnek: 1999 ya da 2003 gibi
"yday" Yılın gününün sayısal gösterimi 0'dan 365'e kadar
"weekday" Haftanın gününün metinsel tam gösterimi Sunday'dan Saturday'ye
"month" Ayın metinsel tam gösterimi, Ocak ya da Mart gibi January'dan December'a kadar
0 Saniyeler, Unix Zaman Başlangıcından itibaren, time() işlevi tarafından döndürülen ve date() işleviyle kullanılan değerlerle benzerdir. Sisteme Bağımlı, genellikle -2147483648 ile 2147483647 arasında.

Sürüm Bilgisi

Sürüm: Açıklama
8.0.0 zaman_damgası artık null olabiliyor.

Örnekler

Örnek 1 - getdate() örneği

<?php
$bugun
= getdate();
print_r($bugun);
?>

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

Array
(
    [seconds] => 40
    [minutes] => 58
    [hours]   => 21
    [mday]    => 17
    [wday]    => 2
    [mon]     => 6
    [year]    => 2003
    [yday]    => 167
    [weekday] => Salı
    [month]   => Haziran
    [0]       => 1055901520
)

Ayrıca Bakınız

  • date() - Unix zaman damgasını biçimlendirir
  • idate() - Yerel zaman/tarih kısmını tamsayı olarak biçimlendirir
  • localtime() - Yerel zamanı getirir
  • time() - Geçerli Unix zaman damgasını döndürür
  • setlocale() - Yereli ayarlar

add a note add a note

User Contributed Notes 6 notes

up
33
vimal866 at gmail dot com
8 years ago
Andre's code will throw an error. for the following line
   
     $d = $todayh[mday];
     $m = $todayh[mon];
     $y = $todayh[year];

"Notice : Undefined constant mday ,mon,year"

As is, it was looking for constants called mday, mon, year etc. When it doesn't find such a constant, PHP interprets it as a string.

like any other request it should be wrapped in quotes like this

     $d = $todayh['mday'];
     $m = $todayh['mon'];
     $y = $todayh['year'];
up
19
Yura Pylypenko (plyrvt at mail dot ru)
20 years ago
In addition to canby23 at ms19 post:
It's a very bad idea to consider day having 24 hours (86400 secs), because some days have 23, some - 25 hours due to daylight saving changes. Using of mkdate() and strtotime() is always preferred. strtotime() also has a very nice behaviour of datetime manipulations:
<?php
echo strtotime ("+1 day"), "\n";
echo
strtotime ("+1 week"), "\n";
echo
strtotime ("+1 week 2 days 4 hours 2 seconds"), "\n";
echo
strtotime ("next Thursday"), "\n";
echo
strtotime ("last Monday"), "\n";
?>
up
-13
andre at anlex dot co dot za
17 years ago
I thought best to show a posseble way to go about bypassing the end month issue where the first day in a new month will have the monday of the week that it falls in - in the old month. Use the numbering of days as the constant and work you way from there.

Example:
<?php
//-----------------------------
$now = time();
$num = date("w");
if (
$num == 0)
{
$sub = 6; }
else {
$sub = ($num-1); }
$WeekMon  = mktime(0, 0, 0, date("m", $now)  , date("d", $now)-$sub, date("Y", $now));    //monday week begin calculation
$todayh = getdate($WeekMon); //monday week begin reconvert

$d = $todayh[mday];
$m = $todayh[mon];
$y = $todayh[year];
echo
"$d-$m-$y"; //getdate converted day

?>

Allot less code makes everyone happy..
up
-8
info at ajawbk dot com
5 years ago
another gmgetdate that is a little faster/suscint (no loops).

<?php
function gmgetdate2($ts = null){
       
$k = array('seconds','minutes','hours','mday',
               
'wday','mon','year','yday','weekday','month',0);
        return(
array_combine($k,split(":",
               
gmdate('s:i:G:j:w:n:Y:z:l:F:U',is_null($ts)?time():$ts))));
        }
?>

https://ajawbk.com/
up
-74
timforte at gmail dot com
16 years ago
It's worth noting that this is local time, not UTC/GMT - gmgetdate doesn't exist :(.

The most logical way to handle date arithmetic without hitting DST problems is to work in UTC...

<?php
function add_days($my_date,$numdays) {
 
$date_t = strtotime($my_date.' UTC');
  return
gmdate('Y-m-d',$date_t + ($numdays*86400));
}
?>

[it's even faster if you use gmmktime instead of strtotime]
up
-82
eric dot schultz at NOSPAM dot CyVon dot com
15 years ago
Here is another gmgetdate that is a little faster/suscint (no loops).

<?php
function gmgetdate2($ts = null){
       
$k = array('seconds','minutes','hours','mday',
               
'wday','mon','year','yday','weekday','month',0);
        return(
array_combine($k,split(":",
               
gmdate('s:i:G:j:w:n:Y:z:l:F:U',is_null($ts)?time():$ts))));
        }
?>

It also returns the values in the same order as getdate.
To Top