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

PHP
WINDOWS下安装MySQL
PHP 制作 网站/服务器 监视脚本
用PHP和CSS制作活动按钮
PHP 单件模式
PHP MVC模式,类封装以及HACK
PHP 中使用正则表达式
PHP 防止 SQL 注入攻击
PHP 跨站点脚本攻击
PHP 防止用户操纵 GET 变量
PHP 防止远程表单提交

PHP 中的 strtotime() 函数


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

Definition and Usage
定义和用法

The strtotime() function parses an English textual date or time into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 GMT).
strtotime()函数的作用是:将任何英文文本的日期时间描述解析为Unix时间戳(从1970年1月1日(GMT)起经过的秒数)。

Syntax
语法

strtotime(time,now)

Parameter参数 Description描述
time Required. Specifies the time string to parse
必要参数。指定需要被解析的时间字符串。
now Optional. Specifies the timestamp used to calculate the returned value. If this parameter is omitted, current time is used
可选参数。指定用来计算返回值的时间戳。如果这个参数被忽略,那么将默认使用当前时间


Tips and Notes
注意点

Note: If the year is specified in a two-digit format, values between 0-69 are mapped to 2000-2069 and values between 70-100 are mapped to 1970-2000.
注意:如果时间是以两位数字的格式指定的,那么数字“0-69”指的是2000-2069年,数字“70-100”指的是1970-2000年。

Note: In PHP 5.1.0 this function returns false on failure (earlier versions returns -1).
注意:在 PHP 5.1.0版本中,如果函数失效,它将返回false(早期版本将返回 -1)。


Example
案例

<?php
echo(strtotime("now") . "<br />");
echo(strtotime("3 October 2005") . "<br />");
echo(strtotime("+5 hours") . "<br />");
echo(strtotime("+1 week") . "<br />");
echo(strtotime("+1 week 3 days 7 hours 5 seconds") . "<br />");
echo(strtotime("next Monday") . "<br />");
echo(strtotime("last Sunday"));
?>

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

1138614504
1128290400
1138632504
1139219304
1139503709
1139180400
1138489200

评论 (0) All

登陆 | 还没注册?