Jquery中文网 www.jquerycn.cn
Jquery中文网 >  脚本编程  >  php  >  正文 php时间戳函数 strtotime 应用实例

php时间戳函数 strtotime 应用实例

发布时间:2015-07-08   编辑:www.jquerycn.cn
int strtotime ( string time [, int now]) 预期接受一个包含英文日期格式的字符串并尝试将其解析为 UNIX 时间戳。

如果 time 的格式是绝对时间则 now 参数不起作用。
如果 time 的格式是相对时间则其所相对的时间由 now 提供,或者如果未提供 now 参数时用当前时间。失败时返回 -1。

下面给出二个小例子,供大家参考。
例1:
 

复制代码 代码示例:
<?php
/*
from:http://www.jquerycn.cn
@date:2013-02-22
*/
echo strtotime ("now"), "\n";
echo strtotime ("10 September 2000"), "\n";
echo strtotime ("+1 day"), "\n";
echo strtotime ("+1 week"), "\n";
echo strtotime ("+1 week 2 days 4 hours 2 seconds"), "\n";
echo strtotime ("next Thursday"), "\n";
echo strtotime ("last Monday"), "\n";
?>

例2:
 

复制代码 代码示例:
<?php
/*
from:http://www.jquerycn.cn
@date:2013-02-22
*/
$str = 'Not Good';
if (($timestamp = strtotime($str)) === -1) {
echo "The string ($str) is bogus";
} else {
echo "$str == ". date('l dS of F Y h:i:s A',$timestamp);
}
?>
 

这个效果与使用mktime()是一样的。

您可能感兴趣的文章:
php 创建以unix时间戳命名的文件夹
php 时间数据转换为时间戳代码
php 时间戳函数总结与示例
php时间函数strtotime的深入理解
php中的UNIX时间戳函数strtotime
如何实现转换php时间戳
php日期函数的简单示例代码
php获取本周、本月第一天与最后一天的时间戳
php时间戳函数 strtotime 应用实例
PHP中strtotime函数用法举例

[关闭]