中国石凳联盟 登录注册

Php部分常见问题总结

Satriani··6 回复·317 浏览

发表回复
函数:date()
--------------------------------------------------------------------------------


日期与时间函数库

date
将服务器的时间格式化。
语法: string date(string format, int )
返回值: 字符串
函数种类: 时间日期



内容说明

返回值的字符串依配置的格式来决定。若有传入时间戳记值,则将时间戳记格式化返回;若无传入时间戳记值,则将目前服务器的时间格式化返回。要将日期转为其它的语系格式,应使用setlocale() 及 strftime() 二个函数。字符串格式化的选项如下:

a - "am" 或是 "pm"
A - "AM" 或是 "PM"
d - 几日,二位数字,若不足二位则前面补零 如: "01" 至 "31"
D - 星期几,三个英文字母 如: "Fri"
F - 月份,英文全名 如: "January"
h - 12 小时制的小时 如: "01" 至 "12"
H - 24 小时制的小时 如: "00" 至 "23"
g - 12 小时制的小时,不足二位不补零 如: "1" 至 12"
G - 24 小时制的小时,不足二位不补零 如: "0" 至 "23"
i - 分钟 如: "00" 至 "59"
j - 几日,二位数字,若不足二位不补零 如: "1" 至 "31"
l - 星期几,英文全名 如: "Friday"
m - 月份,二位数字,若不足二位则在前面补零 如: "01" 至 "12"
n - 月份,二位数字,若不足二位则不补零 如: "1" 至 "12"
M - 月份,三个英文字母 如: "Jan"
s - 秒 如: "00" 至 "59"
S - 字尾加英文序数,二个英文字母 如: "th","nd"
t - 指定月份的天数 如: "28" 至 "31"
U - 总秒数
w - 数字型的星期几,如: "0" (星期日) 至 "6" (星期六)
Y - 年,四位数字 如: "1999"
y - 年,二位数字 如: "99"
z - 一年中的第几天 如: "0" 至 "365"
其它不在上列的字符则直接列出该字符。



使用范例

范例一:
?
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)))
?
范例二:
?
$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)
?

点赞0 收藏
靠,还说支持PHP,你N个网站没一个用PHP写的,我靠
Being a devil is the same as being a human. We should be kind. If we are kind, we are not a devil, we are a hybrid.
点赞0 收藏
你不要逃避问题
Being a devil is the same as being a human. We should be kind. If we are kind, we are not a devil, we are a hybrid.
点赞0 收藏
逃避说明不了问题,快回答正题
Being a devil is the same as being a human. We should be kind. If we are kind, we are not a devil, we are a hybrid.
点赞0 收藏
发表回复
发表回复