教程集 www.jiaochengji.com
教程集 >  脚本编程  >  php  >  正文 php中的UNIX时间戳函数strtotime

php中的UNIX时间戳函数strtotime

发布时间:2016-02-24   编辑:jiaochengji.com
本文介绍下,php中的一个时间戳函数strtotime(),并为大家举一个例子,以帮助大家的学习与理解。有需要的朋友,可以参考下。

strtotime函数

int strtotime ( string time [, int now]) 本函数预期接受一个包含英文日期格式的字符串并尝试将其解析为 UNIX 时间戳。
如果 time 的格式是绝对时间则 now 参数不起作用。如果 time 的格式是相对时间则其所相对的时间由 now 提供,或者如果未提供 now 参数时用当前时间。失败时返回 -1。

例1,
 

复制代码 代码示例:
<?php
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
$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 strtotime函数的用法,还可以参考:
PHP strtotime函数详细介绍
PHP中strtotime函数用法举例
php中strtotime()与mktime() 的Y2K38漏洞 2038年问题
php时间戳函数 strtotime 应用实例
php中strtotime的函数效率

您可能感兴趣的文章:
php 创建以unix时间戳命名的文件夹
php 时间数据转换为时间戳代码
php字符串转时间戳
php时间转换unix时间戳实例
php时间函数strtotime的深入理解
PHP中strtotime函数用法举例
php中的UNIX时间戳函数strtotime
php 时间戳函数总结与示例
php时间戳转换
php取一个月的第一天的代码

[关闭]
~ ~