Home > php教程 > php手册 > body text

php 时间函数: PHP的日期,时间函数

WBOY
Release: 2016-06-21 08:49:29
Original
1271 people have browsed it

date("Y-m-d",time())获取特定格式的时间字符串。 time()是时间戳值,也可以省略,默认当前时间。也可以填写数值。
PHP中所有函数都是UNIX纪元的,即从1970年1月1日开始的。日期是从这个时候开始的秒数。当一个函数调用从这时候计的秒数时,就把它当作(timestamp)时间戳。
本地时间函数
1. string date(string format,inieger timestamp)
该函数返回一个表示时间的字符串,是由string format 控制的。
如:

print(date("Y年 m月d日");//输出当前,年月日.
print(date("Y年 m月d日",60*60*24*365*10);//输出1980年1月1日.
?>
也许你会问,怎麽没有timestamp呢?若timestamp为空时,或不写时,表示使用当前时间一刻timestamp.
表示年份的控制符: Y---四位的年份 y---两位的年份
表示月份的控制符: m---从1-12的月份 F---英文月份名 M---简写的月份名
表示日号的控制符: d---前面有0的月份中日期 j--前面没有0的日号
表示星期的控制符: l--英文星期 D--简写的星期
表示小时的控制符: h--从1到12小时 H---从0到23的小时
表示上下午的控制符 a ---am或pm A---AM或PM
表示分钟的控制符: i---取值00-59
另外的 z--一年中的日期
取一个月中的天数:echo date('t',mktime(1,1,1, month,1, year));
2. array getdate(integer timestamp)
该函数返回一个矩阵.
如:

$current_date=getdate();
print($current_date("hours"));
print($current_date("minutes");
print($current_date("seconds");
?>
说明:
元素 描述
hours 24小时格式的小时
mday 月份中日期
minutes 分钟
mon 数字形式的月份
month 月份全称
seconds 秒数
wday 从0到6的数字形式的星期几
weekday 星期几的名称
year 年份
0 时间戳即从1970年1月1日到现在的秒数
yday 一年中数字形式的日期
3. boolean checkdate(integer month,integer day,integer year) 本文链接http://www.cxybl.com/html/wlbc/Php/20130622/38772.html



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!