当前位置: 首页 > 网络学院 > 服务端脚本教程 > PHP > date() 函数

PHP
php 无限分类的实现
常用PHP代码
windows下安装配置php视频教程
MySQL数据库结构和数据的导出和导入
PHP实现 IP Whois 查询
PHP5 this,self和parent关键字详解
PHP 安全技巧连载 #1[译]
PHP 安全技巧连载 #2[译]
PHP 安全技巧连载 #3[译]
PHP 安全技巧连载 #4[译]
PHP 安全技巧连载 #5[译]
PHP 安全技巧连载 #6[译]
PHP 安全技巧连载 #7[译]
PHP 安全技巧连载 #8[译]
PHP 安全技巧连载 #9[译]
PHP 安全技巧连载 #10[译]
PHP 安全技巧连载 #11[译]
PHP error_reporting的使用
PHP 安全技巧连载 #12
使用PHP做Linux/Unix守护进程

PHP 中的 date() 函数


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 491 ::
收藏到网摘: n/a

Definition and Usage
定义和用法

The date() function formats a local time/date.
date()函数指定了一个本地时间/日期的格式

Syntax
语法

date(format,timestamp)

Parameter参数 Description描述
format Required. Specifies how to return the result:
必要参数。指定返回结果的方式:
  • d - The day of the month (from 01 to 31)
    d – 一个月包含的天数(从01号到31号)
  • D - A textual representation of a day (three letters)
    D – 关于某一天是星期几的文本陈述(用三个字母表示,如:Jan、Fre等)
  • j - The day of the month without leading zeros (1 to 31)
    j -一个月包含的天数,数字前不包含0(从1号到31号)
  • l (lowercase 'L') - A full textual representation of a day
    l(‘L’的小写形式)- 表示当天星期几的完整文本
  • N - The ISO-8601 numeric representation of a day (1 for Monday through 7 for Sunday)
    N – 用ISO-8061的数字格式表示一天是星期几(如:1表示Monday[星期一]、7表示Sunday[星期日])
  • S - The English ordinal suffix for the day of the month (2 characters st, nd, rd or th. Works well with j)
    S – 在日子后加英文后缀(它有两个英文字母组成:st、nd或th,它通常和上述的“j”在一起使用,如:1st,2nd,3rd,4th)
  • w - A numeric representation of the day (0 for Sunday through 6 for Saturday)
    w – 表示星期几的数字(0表示Sunday[星期日],6表示Saturday[星期六])
  • z - The day of the year (from 0 through 365)
    z – 一年当包含的天数(从0到365)
  • W - The ISO-8601 week number of year (weeks starting on Monday)
    W - 用ISO-8061的数字格式表示一年中的星期(始于Monday[星期一])
  • F - A full textual representation of a month (January through December)
    F – 关于月份的完整文本描述(从January[一月份]开始到Decemeber[十二月份])
  • m - A numeric representation of a month (from 01 to 12)
    m – 用数值形式表示月份(从01到12)
  • M - A short textual representation of a month (three letters)
    M – 用于表示月份的简写文本形式(三个字母表示,如:Jan、Fre……)
  • n - A numeric representation of a month, without leading zeros (1 to 12)
    n -用数值形式表示月份,数字前不包含零(从1到12)
  • t - The number of days in the given month
    t – 给定月份中包含的天数
  • L - Whether it's a leap year (1 if it is a leap year, 0 otherwise)
    L – 指定是否是闰年(1表示闰年;0不是)
  • o - The ISO-8601 year number
    o – ISO-8601标准下的年份数字
  • Y - A four digit representation of a year
    Y – 表示年份的四位数字
  • y - A two digit representation of a year
    y – 用两位数的形式表示的年份数字
  • a - Lowercase am or pm
    a – 小写形式表示:am 或 pm
  • A - Uppercase AM or PM
    A – 大写形式表示:am 或 pm
  • B - Swatch Internet time (000 to 999)
    B – Swatch网络时间(000到999)
  • g - 12-hour format of an hour (1 to 12)
    g – 12小时格式(1到12)
  • G - 24-hour format of an hour (0 to 23)
    G – 24小时格式(0到23)
  • h - 12-hour format of an hour (01 to 12)
    h – 12小时格式(01到12)
  • H - 24-hour format of an hour (00 to 23)
    H – 24小时格式(00到23)
  • i - Minutes with leading zeros (00 to 59)
    i– 分钟表示格式(00到59)
  • s - Seconds, with leading zeros (00 to 59)
    s – 秒表示格式(00到59)
  • e - The timezone identifier (Examples: UTC, Atlantic/Azores)
    e – 时区标志符(如:UTC, Atlantic/Azores)
  • I (capital i) - Whether the date is in daylights savings time (1 if Daylight Savings Time, 0 otherwise)
    I(“i”的大写形式)- 指名是否是夏令时(1表示夏令时;0表示不是夏令时)
  • O - Difference to Greenwich time (GMT) in hours (Example: +0100)
    O – 表示GMT格式时间的差异(如:+0100)
  • T - Timezone setting of the PHP machine (Examples: EST, MDT)
    T – PHP服务器的时区设置(如:EST, MDT)
  • Z - Timezone offset in seconds. The offset west of UTC is negative, and the offset east of UTC is positive (-43200 to 43200)
    Z – 以秒计算的时区。西部的UTC为负数,东部的UTC是正数(-43200到43200)
  • c - The ISO-8601 date (e.g. 2004-02-12T15:19:21+00:00)
    c – ISO-8601标准的日期(例如:2004-02-12T15:19:21+00:00)
  • r - The RFC 2822 formatted date (e.g. Thu, 21 Dec 2000 16:01:07 +0200)
    r – RFC 2822格式的日期(例如:Thu, 21 Dec 2000 16:01:07 +0200)
  • U - The seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)
    U – 以Unix Epoch为准计算经过的秒数(January 1 1970 00:00:00 GMT)
timestamp Optional.
可选参数。指定时间戳。


Example
案例

<?php
echo("Result with date():<br />");
echo(date("l") . "<br />");
echo(date("l dS of F Y h:i:s A") . "<br />");
echo("Oct 3,1975 was on a ".date("l", mktime(0,0,0,10,3,1975))."<br />");
echo(date(DATE_RFC822) . "<br />");
echo(date(DATE_ATOM,mktime(0,0,0,10,3,1975)) . "<br /><br />");
echo("Result with gmdate():<br />");
echo(gmdate("l") . "<br />");
echo(gmdate("l dS of F Y h:i:s A") . "<br />");
echo("Oct 3,1975 was on a ".gmdate("l", mktime(0,0,0,10,3,1975))."<br />");
echo(gmdate(DATE_RFC822) . "<br />");
echo(gmdate(DATE_ATOM,mktime(0,0,0,10,3,1975)) . "<br />");
?>

The output of the code above could be something like this:
上述代码将输出下面的结果:

Result with date():
Tuesday
Tuesday 24th of January 2006 02:41:22 PM
Oct 3,1975 was on a Friday
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
Oct 3,1975 was on a Thursday
Tue, 24 Jan 2006 13:41:22 GMT
1975-10-02T23:00:00+0000

评论 (0) All

登陆 | 还没注册?