日期与时间函数库:date

date

(PHP3 , PHP4)

date ---&">nbsp; 将本地的时间/日期格式化

语法 : string date (string format [, int timestamp])

说明 :

使用给予的timestamp按照格式化字符串传回一格式化字符串,如果没有给予timestamp则使用本地的时间。

以下是格式化字符串中认定的字元:

a - "am" 或 "pm"

A - "AM" 或 "PM"

B - 网际网路时间样本

d - 几日,例如:" 01" 到 " 31"

D - 几日,以3个英文字表示,例如:" Fri "

F - 几月,以英文全名表示,例如:" January "

g - 小时,12小时制不足2位数不补0,例如:" 1" 到 " 12 "

G - 小时,24小时制不足2位数不补0,例如:" 0 " 到 " 23 "

h - 小时,12小时制,例如:" 01" 到 " 12 "

H - 小时,24小时制,例如:" 00 " 到 " 23 "

i - 几分,例如:" 00 " 到 " 59 "

I (大写的 i) - "1" if Daylight Savings Time, "0" otherwise.

j - 几日,不足2位数不补0,例如:" 1" 到 " 31"

l (小写的 'L') - 几日,以英文全名表示,例如:"Friday"

L - 布林值,判断是否为闰年,例如:" 0" 或 " 1"

m - 几月,例如:" 01" 到 " 12"

M - 几月,以3个英文字表示,例如:"Jan"

n - 几月,不足2位数不补0,例如:" 1" 到 "12"

s - 几秒,例如:" 01" 到 " 59"

S - 以英文后2个字表示,例如:"th","nd"

t - 当月的天数,例如:" 28" 到 " 31"

T - 这个机器的时间区域设定,例如 :"MDT"

U - 总秒数

w - 以数字表示星期几,例如:" 0" 到 " 6"

Y - 几年,以4位数表示,例如:" 1999"

y - 几年,以2位数表示,例如:"99"

z - 一年中的第几天,例如:" 0" 到 " 365"

Z - 在短时间内时间区域补偿(timezone offset) ,例如:"-43200" to "43200"

在格式化字符串中未被认出的字元将会被列出来,当使用gmdate( )时"Z"格式将总是传回"0"。

Example :

<?php

print (date ("l dS of F Y h:i:s A"));

print ("July 1, 2000 is on a " . date ("l", mktime(0,0,0,7,1,2000)));

?>

它可能会和date( )与mktime( )一起使用,来找出是将来或是过去的日期。

Example :

<?php

$tomorrow  = mktime (0,0,0,date("m")  ,date("d")+1,date("Y"));

$lastmonth = mktime (0,0,0,date("m")-1,date("d"),  date("Y"));

$nextyear  = mktime (0,0,0,date("m"),  date("d"),  date("Y")+1);

?>

将日期格式化成其它的语言(languages),你应该使用setlocal( )和strftime( )函数。

时间: 2024-09-20 12:34:08

日期与时间函数库:date的相关文章

日期与时间函数库:mktime

mktime (PHP3 , PHP4) mktime ---&http://www.aliyun.com/zixun/aggregation/37954.html">nbsp; 取得日期的UNIX时间戳记 语法 : int mktime (int hour, int minute, int second, int month, int day, int year [, int is_dst]) 说明 : 警告 : 此函数参数的顺序和正规的Unix mktime( )中参数的顺序不

日期与时间函数库:gmstrftime

gmstrftime (PHP3 >= 3.http://www.aliyun.com/zixun/aggregation/37104.html">0.12 , PHP4 >= 4.0RC2) gmstrftime ---  按照场所设定将格林威治时间/日期格式化 语法 : string gmstrftime (string format, int timestamp) 说明 : 作用与strftime( )相同,不同处在于这个函数传回的时间是格林威治标准时间,例如当执行在东部

日期与时间函数库:gmdate

gmdate (PHP3 , PHP4) gmdate ---&http://www.aliyun.com/zixun/aggregation/37954.html">nbsp; 取得目前的时间 语法 : string gmdate (string format, int timestamp) 说明 : 和date( )相同,不同处在于这个函数传回的是格林威治标准时间,例如当以下范例在芬兰(GMT + 0200)执行时,下面的第一行会列出"Jan 01 1998 00:0

日期与时间函数库:strtotime

strtotime (PHP3 >= 3.http://www.aliyun.com/zixun/aggregation/37104.html">0.12 , PHP4 >= 4.0b2) strtotime ---  剖析任何英文的日期时间成为UNIX时间戳记 语法 : int strtotime (string time [, int now]) 说明 : 给予此函数一包含英文日期格式的字符串,将会试着去剖析此字符串成为UNIX时间戳记 Example : <?php

日期与时间函数库:getdate

getdate (PHP3 , PHP4) getdate ---&http://www.aliyun.com/zixun/aggregation/37954.html">nbsp; 取得日期/时间资讯 语法 : array getdate (int timestamp) 说明 : 传回组合的数组,包含了timestamp的日期资讯,下列为数组的元素: "seconds" - 秒 "minutes" - 分 "hours"

日期与时间函数库:time

time (PHP3 , PHP4) time ---&http://www.aliyun.com/zixun/aggregation/37954.html">nbsp; 传回目前UNIX时间戳记 语法 : int time(void); 说明 : 传回从Unix时期(January 1 1970 00:00:00 GMT)到现在的总秒数. 参考 : date( )

日期与时间函数库:gettimeofday

gettimeofday (PHP3 >=3.0.7 , PHP4 >= 4.0b4) gettimeofday ---&http://www.aliyun.com/zixun/aggregation/37954.html">nbsp; 取得目前的时间 语法 : array gettimeofday (void) 说明 : 这是个gettimeofday(2)的介面,它从呼叫系统传回一包含了资料的组合数组. "sec" - 秒 "usec&

日期与时间函数库:gmmktime

gmmktime (PHP3 , PHP4) gmmktime ---&http://www.aliyun.com/zixun/aggregation/37954.html">nbsp; 取得UNIX时间戳记的格林威治时间 语法 : int gmmktime (int hour, int minute, int second, int month, int day, int year [, int is_dst]) 说明 : 和mktime( )相同,不同处在于参数是格林威治时间.

日期与时间函数库:localtime

localtime (PHP4 >= 4.0RC2) localtime ---&http://www.aliyun.com/zixun/aggregation/37954.html">nbsp; 取得当地时间 语法 : array localtime ([int timestamp [, bool is_associative]]) 说明 : localtime( )传回一组合数组,localtime( )的第一个参数是个timestamp,如果没有给予则使用目前时间,如果