The date () function in PHP

Source: Internet
Author: User
Tags time zones rfc

Instance

Formats the local date and time and returns the formatted date string:

<?php//Prints the Dayecho date ("L"). "<br>";//Prints the day, date, month, year, time, AM or Pmecho date ("L JS of F Y h:i:s A");? >

  

Definition and usage

The date () function formats the local date and time and returns the formatted date string.

Syntax Date ( format,timestamp);

Parameters Description
Format Necessary. Specifies the format of the output date string. You can use the following characters:
  • D-the day of the one month (from 01 to 31)
  • D-The text representation of the Day of the week (denoted by three letters)
  • J-the day of the one month without leading 0 (1 to 31)
  • L (lowercase form of ' l ')-Full text representation of the day of the week
  • N-ISO-8601 number format representation of the Day of the week (1 for monday[Monday], 7 for sunday[Sunday])
  • S-The English ordinal suffix of the first day of the one month (2 characters: St, ND, RD, or th. Used with J)
  • W-Number representation of the day of the week (0 = sunday[Sunday], 6 = saturday[Saturday])
  • Z-the day ordinal of a year (from 0 to 365)
  • W-a ISO-8601 number format that represents the weekday number of the year (starting from monday[Monday] per week)
  • F-Full text representation of the month (january[January] to december[December])
  • M-Number representation of the month (from 01 to 12)
  • M-month short text representation (denoted by three letters)
  • N-numeric representation of the month without leading 0 (1 to 12)
  • T-number of days included in a given month
  • L-whether it is a leap year (1 if it is a leap year, otherwise 0)
  • Year numbers under the o-iso-8601 standard
  • Y-the four-digit number of years represents
  • Y-two-digit representation of the year
  • A-lowercase form means: AM or PM
  • A-Uppercase indicates: AM or PM
  • B-swatch Internet time (000 to 999)
  • G-12 hours, without leading 0 (1 to 12)
  • G-24-hour system without leading 0 (0 to 23)
  • H-12 Hour, with leading 0 (01 to 12)
  • H-24-hour system with leading 0 (00 to 23)
  • I-min, with leading 0 (00 to 59)
  • S-sec with leading 0 (00 to 59)
  • U-microseconds (New in PHP 5.2.2)
  • e-time zone identifier (for example: UTC, GMT, Atlantic/azores)
  • I (uppercase Form I)-whether the date is in daylight saving time (1 if daylight saving time, otherwise 0)
  • O-Greenwich mean GMT (GMT) difference, in hours (example: +0100)
  • P-Greenwich Mean (GMT) difference, in Hours:minutes (New in PHP 5.1.3)
  • T-Shorthand for time zones (example: EST, MDT)
  • Z-The time zone offset in seconds. The offset for the time zone west of UTC is a negative number (-43200 to 50400)
  • Date of c-iso-8601 standard (e.g. 2013-05-05t16:34:42+00:00)
  • R-RFC 2822 format date (e.g. Fri, April 2013 12:01:05 +0200)
  • U-Number of seconds elapsed since the Unix era (January 1 1970 00:00:00 GMT)

You can also use the following predefined constants (available starting from PHP 5.1.0):

    • Date_atom-atom (ex: 2013-04-12t15:52:01+00:00)
    • Date_cookie-http Cookies (ex: Friday, 12-apr-13 15:52:01 UTC)
    • date_iso8601-iso-8601 (ex: 2013-04-12t15:52:01+0000)
    • DATE_RFC822-RFC 822 (example: Fri, April 13 15:52:01 +0000)
    • DATE_RFC850-RFC 850 (example: Friday, 12-apr-13 15:52:01 UTC)
    • DATE_RFC1036-RFC 1036 (Example: Fri, April 13 15:52:01 +0000)
    • DATE_RFC1123-RFC 1123 (Example: Fri, April 2013 15:52:01 +0000)
    • DATE_RFC2822-RFC 2822 (Fri, April 2013 15:52:01 +0000)
    • date_rfc3339-Same as Date_atom (starting with PHP 5.1.3)
    • Date_rss-rss (Fri, 2013 15:52:01 +0000)
    • DATE_W3C-World Wide Web Consortium (ex: 2013-04-12T15:52:01+00:00)
Timestamp Optional. A Unix timestamp that specifies an integer. The default is the current local time (hour ()).
Technical details

return value: Returns the formatted date string if successful, and returns FALSE if the failure is e_warning.
PHP version: 4 +
Update log: PHP 5.1.0: Added e_strict and e_notice time zone errors. The valid range timestamp is from December 13, 1901 20:45:54 GMT Friday to January 19, 2038 03:14:07 GMT Tuesday. Prior to 5.1.0, the timestamp on some systems (such as Windows) was limited from 01-01-1970 to 19-01-2038.
PHP 5.1.1: New standard date/time format constants for specifying the format parameter.

The date () function in PHP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.