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

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 中的 mktime() 函数


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

Definition and Usage
定义和用法

The mktime() function returns the Unix timestamp for a date.
mktime()函数的作用是:返回一个日期的Unix时间戳。

This timestamp contains the number of seconds between the Unix Epoch (January 1 1970 00:00:00 GMT) and the time specified.
这个时间戳包含了Unix Epoch (January 1 1970 00:00:00 GMT)和指定时间之间相隔的秒数。

Syntax
语法

mktime(hour,minute,second,month,day,year,is_dst)

Parameter参数 Description描述
hour Optional. Specifies the hour
可选参数。指定小时
minute Optional. Specifies the minute
可选参数。指定分钟
second Optional. Specifies the second
可选参数。指定秒数
month Optional. Specifies the numerical month
可选参数。指定月份
day Optional. Specifies the day
可选参数。指定日
year Optional. Specifies the year. The valid range for year is on some systems between 1901 and 2038. However this limitation is overcome in PHP 5
可选参数。指定年份。在有些系统中,年份是基于1901年和2038年之间的。然而这些旨在PHP 5以上的版本中支持
is_dst Optional. Set this parameter to 1 if the time is during daylight savings time (DST), 0 if it is not, or -1 (the default) if it is unknown. If it's unknown, PHP tries to find out itself (which may cause unexpected results). Note: This parameter became deprecated in PHP 5. The new timezone handling features should be used instead.
可选参数。如果是夏令时[dst],则此参数为1;如不是则为0;如果不确定则为-1。如果是不确定的情况,那么PHP将会自行查找结果(这可能导致不可预想的结果)
注意:我们不提倡在PHP 5种使用该参数。我们应该使用别的方法来代替使用这种“新时区处理方法”


Tips and Notes
注意点

Note: If the arguments are invalid, the function returns false (PHP versions before 5.1 returns -1).
注意:如果自变量是无效的,函数返回False(如果是PHP5.1以前的版本则返回 -1)。


Example
案例

The mktime() function is useful for doing date arithmetic and validation. It will automatically calculate the correct value for out-of-range input:
mktime()函数对计算日期和确认日期有效性来说是非常有用的。它将自动为超过范围以外的输入计算正确的值:

<?php
echo(date("M-d-Y",mktime(0,0,0,12,36,2001))."<br />");
echo(date("M-d-Y",mktime(0,0,0,14,1,2001))."<br />");
echo(date("M-d-Y",mktime(0,0,0,1,1,2001))."<br />");
echo(date("M-d-Y",mktime(0,0,0,1,1,99))."<br />");
?>

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

Jan-05-2002
Feb-01-2002
Jan-01-2001
Jan-01-1999

评论 (0) All

登陆 | 还没注册?