Monday, 20 May 2013

date() in php


PHP date():

    Definition and Usage

    The date() function formats a local time/date.

    Syntax
    <?php date(format,timestamp) ?>
    Example
    <?php echo date("d-m-y h:i:s"); ?>


    Output :
    20-05-13 08:40:15 

    parameterdescription
    dThe day of the month (from 01 to 31)
    DA textual representation of a day (three letters)
    jThe day of the month without leading zeros (1 to 31)
    l(lowercase 'L')A full textual representation of a day
    NThe ISO-8601 numeric representation of a day (1 for Monday through 7 for Sunday)
    SThe English ordinal suffix for the day of the month (2 characters st, nd, rd or th. Works well with j)
    wA numeric representation of the day (0 for Sunday through 6 for Saturday)
    zThe day of the year (from 0 through 365)
    WThe ISO-8601 week number of year (weeks starting on Monday)
    FA full textual representation of a month (January through December)
    mA numeric representation of a month (from 01 to 12)
    MA short textual representation of a month (three letters)
    nA numeric representation of a month, without leading zeros (1 to 12)
    tThe number of days in the given month
    LWhether it's a leap year (1 if it is a leap year, 0 otherwise)
    oThe ISO-8601 year number
    YA four digit representation of a year
    aLowercase am or pm
    AUppercase AM or PM
    BSwatch Internet time (000 to 999)
    g12-hour format of an hour (1 to 12)
    G24-hour format of an hour (0 to 23)
    h12-hour format of an hour (01 to 12)
    H24-hour format of an hour (00 to 23)
    iMinutes with leading zeros (00 to 59)
    sSeconds, with leading zeros (00 to 59)
    eThe timezone identifier (Examples: UTC, Atlantic/Azores)
    I(capital i)Whether the date is in daylights savings time (1 if Daylight Savings Time, 0 otherwise)
    ODifference to Greenwich time (GMT) in hours (Example: +0100)
    TTimezone setting of the PHP machine (Examples: EST, MDT)
    ZTimezone offset in seconds. The offset west of UTC is negative, and the offset east of UTC is positive (-43200 to 43200)
    cThe ISO-8601 date (e.g. 2004-02-12T15:19:21+00:00)
    rThe RFC 2822 formatted date (e.g. Thu, 21 Dec 2000 16:01:07 +0200)
    UThe seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)
    Example
    <?php echo("Result with date():&lt;br /&gt;"); echo(date("l") . "&lt;br /&gt;"); echo(date("l dS \of F Y h:i:s A") . "&lt;br /&gt;"); echo(date(DATE_RFC822) . "&lt;br /&gt;"); echo(date(DATE_ATOM,mktime(0,0,0,10,3,1975)) . "&lt;br /&gt;"); echo("Result with gmdate():&lt;br /&gt;"); echo(gmdate("l") . "&lt;br /&gt;"); echo(gmdate("l dS \of F Y h:i:s A") . "&lt;br /&gt;"); echo(gmdate(DATE_RFC822) . "&lt;br /&gt;"); echo(gmdate(DATE_ATOM,mktime(0,0,0,10,3,1975)) . "&lt;br /&gt;"); ?>


    The output of the code above could be something like this:
    Result with date():
    Tuesday Tuesday 24th of January 2006 02:41:22 PM Tue, 24 Jan 2006 14:41:22 CET 1975-10-03T00:00:00+0100
    Result with gmdate():
    Tuesday Tuesday 24th of January 2006 01:41:22 PM Tue, 24 Jan 2006 13:41:22 GMT 1975-10-02T23:00:00+0000

No comments:

Post a Comment