PHP gmdate() function

Example

Format the GMT/UTC date and time and return the formatted date string:

<?php
// Output day of the week
echo gmdate("l") . "<br>";
// Output day of the week, day, month, year, time, AM or PM
echo gmdate("l jS \of F Y h:i:s A");
?>

Running Example

Definition and Usage

The gmdate() function formats the GMT/UTC date and time and returns the formatted date string.

Syntax

gmdate(format,timestamp);
Parameter Description
format

Required. Specify the format of the output date string. The following characters can be used:

  • d - The day of the month (from 01 to 31)
  • D - The text representation of the day of the week (represented by three letters)
  • j - The day of the month without leading zeros (1 to 31)
  • l (the lowercase form of 'L') - The full text representation of the day of the week
  • N - The ISO-8601 numeric format representation of the day of the week (1 represents Monday[Monday], 7 represents Sunday[Sunday])
  • S - The ordinal suffix of the day of the month (2 characters: st, nd, rd, or th. Used with j)
  • w - The numeric representation of the day of the week (0 represents Sunday[Sunday], 6 represents Saturday[Saturday])
  • z - The day of the year (from 0 to 365)
  • W - The week number in the year represented in ISO-8601 numeric format (starting from Monday[Monday])
  • F - The full text representation of the month (January[January] to December[December])
  • m - The numeric representation of the month (from 01 to 12)
  • M - The short text representation of the month (represented by three letters)
  • n - The numeric representation of the month without leading zeros (1 to 12)
  • t - The number of days in the given month
  • L - Whether it is a leap year (1 if it is a leap year, otherwise 0)
  • o - The year number under the ISO-8601 standard
  • Y - Τέσσερα ψηφία το έτος
  • y - Δύο ψηφία το έτος
  • a - Μικρογραφία AM/PM (π.π., am/pm)
  • A - Εκτεταμένη μορφή AM/PM (π.π., AM/PM)
  • B - Swatch Internet Time (000 έως 999)
  • g - Ώρες σε 12ωρη βάση χωρίς προέλεγχο (1 έως 12)
  • G - Ώρες σε 24ωρη βάση χωρίς προέλεγχο (0 έως 23)
  • h - Ώρες σε 12ωρη βάση, με προέλεγχο (01 έως 12)
  • H - Ώρες σε 24ωρη βάση, με προέλεγχο (00 έως 23)
  • i - Λεπτά, με προέλεγχο (00 έως 59)
  • s - Δευτερόλεπτα, με προέλεγχο (00 έως 59)
  • u - Μικροδευτερόλεπτα (υποστηρίζεται από την έκδοση PHP 5.2.2)
  • e - Η ταυτότητα ζώνης ώρας (π.π., UTC, GMT, Atlantic/Azores)
  • I (i σε πεζά) - Αν η ημερομηνία είναι στη θερινή ώρα (αν ναι, τότε 1, αν όχι, τότε 0)
  • O - Η διαφορά ώρας από το GMT σε ώρες (π.π., +0100)
  • P - Η διαφορά ώρας από το GMT σε ώρες:λεπτά (υποστηρίζεται από την έκδοση PHP 5.1.3)
  • T - Συντομεύσεις ζώνης ώρας (π.π., EST, MDT)
  • Z - Η διαφορά ώρας ζώνης σε δευτερόλεπτα. Η διαφορά ώρας για την Ζώνη UTC είναι αρνητική (-43200 έως 50400)
  • c - Ημερομηνία σε μορφή ISO-8601 (π.π., 2013-05-05T16:34:42+00:00)
  • r - Ημερομηνία σε μορφή RFC 2822 (π.π., Fri, 12 Apr 2013 12:01:05 +0200)
  • U - Το αριθμό των δευτερολέπτων που έχουν περάσει από την αρχή του Unix εποχής (1 Ιανουαρίου 1970 00:00:00 GMT)

Επιπλέον, μπορείτε να χρησιμοποιήσετε τις εξής προκαθορισμένες μονάδες (από την έκδοση PHP 5.1.0):

  • DATE_ATOM - Atom (π.π., 2013-04-12T15:52:01+00:00)
  • DATE_COOKIE - HTTP Cookies (π.π.π., 12-Apr-13 15:52:01 UTC)
  • DATE_ISO8601 - ISO-8601 (π.π., 2013-04-12T15:52:01+0000)
  • DATE_RFC822 - RFC 822 (π.π., 12 Apr 13 15:52:01 +0000)
  • DATE_RFC850 - RFC 850 (π.π.π., 12-Apr-13 15:52:01 UTC)
  • DATE_RFC1036 - RFC 1036 (π.χ. Fri, 12 Apr 13 15:52:01 +0000)
  • DATE_RFC1123 - RFC 1123 (π.χ. Fri, 12 Apr 2013 15:52:01 +0000)
  • DATE_RFC2822 - RFC 2822 (Fri, 12 Apr 2013 15:52:01 +0000)
  • DATE_RFC3339 - Ίδιο με DATE_ATOM (από την έκδοση PHP 5.1.3)
  • DATE_RSS - RSS (Fri, 12 Aug 2013 15:52:01 +0000)
  • DATE_W3C - Διαδίκτυο (π.χ. 2013-04-12T15:52:01+00:00)
timestamp Οptional. Ορίζει το Unix timestamp του αριθμού. Προεπιλεγμένο είναι η τρέχουσα τοπική ώρα (time()).

Τεχνικές λεπτομέρειες

Αποτελεσματικότητα: Εάν επιτυχής, επιστρέφει τη μορφοποιημένη αλφαριθμητική αλληλουχία ημερομηνίας, εάν αποτυγχάνει, επιστρέφει το E_WARNING και FALSE.
Έκδοση PHP: 4+
Ημερολόγιο Ενημερώσεων:

PHP 5.1.0: Η έγκυρη γκάμα του timestamp είναι από 13 Δεκεμβρίου 1901 20:45:54 GMT Παρασκευή μέχρι 19 Ιανουαρίου 2038 03:14:07 GMT Δευτέρα. Στις εκδόσεις πριν από την 5.1.0, σε ορισμένα συστήματα (π.χ. Windows) το timestamp περιορίζεται από 01-01-1970 μέχρι 19-01-2038.

PHP 5.1.1: Προστέθηκε το πρότυπο μορφοποίησης ημερομηνίας/χρόνου, για να καθοριστεί format Παράμετροι.