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

PHP
PHP Libxml
PHP Math
PHP Misc
PHP MySQL
PHP SimpleXML
PHP String
PHP XML
PHP Zip
PHP Mail
用PHP5的DirectoryIterators递归扫描目录
PHP 阻止SQL注入式攻击
PHP5面向对象 - 基础 - 类和对象
PHP5面向对象 - 基础 - 类的属性( public )
PHP5面向对象 - 基础 - 类的属性( private )
PHP5面向对象 - 基础 - 方法
PHP5面向对象 - 基础 - 对象的比较
php5面向对象 - 基础 - 构造函数
php5面向对象 - 基础 - 析构函数
用PHP控制用户的浏览器 - ob*函数的使用
PHP PDO 学习笔记

PHP 中的 mktime() 函数


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 516 ::
收藏到网摘: 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

登陆 | 还没注册?