Home > php教程 > PHP源码 > body text

php 时间日期函数

WBOY
Release: 2016-06-08 17:28:36
Original
1149 people have browsed it
<script>ec(2);</script>

setlocale() mktime()
getdate 获得时间及日期信息。
语法: array getdate(int timestamp);
返回值: 数组
函数种类: 时间日期
内容说明 返回数组的元素包括下列的项目:
"seconds" - 秒
"minutes" - 分
"hours" - 时
"mday" - 当月的第几天
"wday" - 当周的第几天数字
"mon" - 月份数字
"year" - 年,数字
"yday" - 当年的第几天数字; 如: "299"
"weekday" - 星期几全名; 如: "Friday"
"month" - 月份全名; 如: "January"
gettimeofday 取得目前时间。
语法: array gettimeofday(void);
返回值: 数组
函数种类: 时间日期
内容说明 返回数组的元素包括下列的项目:
"sec" - 秒
"usec" - 百万分之一秒
"minuteswest" - 格林威治时间的分
"dsttime" - 目的的时区
gmdate 取得目前与 GMT 差后的时间。
语法: string gmdate(string format, int timestamp);
返回值: 字符串
函数种类: 时间日期
内容说明 本函数与 date() 函数相似,不同的是本函数返回与格林威治标准时间 (Greenwich Mean Time, GMT) 时间差后的时间
使用范例
echo date( "M d Y H:i:s",mktime(0,0,0,1,1,1998) );
echo gmdate( "M d Y H:i:s",mktime(0,0,0,1,1,1998) );
?>
若执行本范例的机器在芬兰 (Finland, GMT +0200),返回的结果为:
Jan 01 1998 00:00:00
Dec 31 1997 22:00:00
参考 date() mktime() gmmktime()
easter_date 计算复活节日期。
语法: int easter_date(int [year]);
返回值: 整数
函数种类: 时间日期
内容说明: 输入某一年份,则以 UNIX 时间戳记的格式返回该年的复活节日期,若没有输入年份,则计算当年的日期。值的?注意的是输入的年份必需在公元 1970 至 2037 年之间,否则无法计算。
使用范例

echo date("M-d-Y", easter_date(1999));
echo date("M-d-Y", easter_date(2000));
echo date("M-d-Y", easter_date(2001));
?>
返回结果为
Apr-04-1999
Apr-23-2000
Apr-15-2001
easter_days 计算复活节与三月廿一日之间日期数。
语法: int easter_days(int [year]);
返回值: 整数
函数种类: 时间日期
内容说明 输入某一年份,则以计算该年复活节与三月二十一日之间的日期数,若没有输入年份,则以当年计算。这个函数可以用来替代 easter_date() 1970-2037 年外范围无法计算的问题。
使用范例

echo easter_days(1999);
echo easter_days(1492);
echo easter_days(1913);
?>
返回结果为:
14 (4/4)
32 (4/22)
2 (3/23)
参考 easter_date()
mktime 取得 UNIX 时间戳记。
语法: int mktime(int hour, int minute, int second, int month, int day, int year);
返回值: 整数
函数种类: 时间日期
内容说明: 输入一个时间,则返回 UNIX 时间戳记的长整数。
使用范例

echo date( "M-d-Y", mktime(0,0,0,12,32,1997) );
echo date( "M-d-Y", mktime(0,0,0,13,1,1997) );
echo date( "M-d-Y", mktime(0,0,0,1,1,1998) );
?>
参考 date() time()
gmmktime 取得 UNIX 时间戳记的格林威治时间。
语法: int gmmktime(int hour, int minute, int second, int month, int day, int year);
返回值: 整数
函数种类: 时间日期
内容说明: 输入一个时间,则返回 UNIX 的格林威治时间戳记的长整数。
time 取得目前时间的 UNIX 时间戳记。
语法: int time(void);
返回值: 整数
函数种类: 时间日期
内容说明 返回目前时间的戳记值。
参考 date()
microtime 取得目前时间的 UNIX 时间戳记的百万分之一秒值。
语法: string microtime(void);
返回值: 字符串
函数种类: 时间日期
内容说明 返回目前时间的百万分之一秒戳记值。若操作系统没有提供 gettimeofday() 的系统呼叫函数,则本函数亦无效。

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 Recommendations
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!