当前位置:编程学习 > php >>

将任何英文文本的日期或时间描述解析为 Unix 时间戳

定义和用法
strtotime() 函数将任何英文文本的日期时间描述解析为 Unix 时间戳。

语法
strtotime(time,now)参数 描述
time 规定要解析的时间字符串。
now 用来计算返回值的时间戳。如果省略该参数,则使用当前时间。 

说明
该函数预期接受一个包含美国英语日期格式的字符串并尝试将其解析为 Unix 时间戳(自 January 1 1970 00:00:00 GMT 起的秒数),其值相对于 now 参数给出的时间,如果没有提供此参数,则用系统当前时间。

该函数将使用 TZ 环境变量(如果有的话)来计算时间戳。自 PHP 5.1.0 起有更容易的方法来定义时区用于所有的日期/时间函数。
此过程在 date_default_timezone_get() 函数页面中有说明。


PHP date_default_timezone_get() 函数
PHP Date / Time 函数
定义和用法
date_default_timezone_get() 函数返回脚本中所有日期时间函数所使用的默认时区。

语法
date_default_timezone_get(void)参数 描述
void 可选。

说明
本函数返回默认时区,使用如下“假定”的顺序:

用 date_default_timezone_set() 函数设定的时区(如果设定了的话)
TZ 环境变量(如果非空)
date.timezone 配置选项(如果设定了的话)
自己推测(如果操作系统支持)
如果以上选择都不成功,则返回 UTC
例子
<?php教程
echo(date_default_timezone_get());
?>输出:

Europe/Paris


返回值
成功则返回时间戳,否则返回 FALSE。在 PHP 5.1.0 之前本函数在失败时返回 -1。
例子
<?php
echo(strtotime("now"));
echo(strtotime("3 October 2005"));
echo(strtotime("+5 hours"));
echo(strtotime("+1 week"));
echo(strtotime("+1 week 3 days 7 hours 5 seconds"));
echo(strtotime("next Monday"));
echo(strtotime("last Sunday"));
?>输出:

1138614504
1128290400
1138632504
1139219304
1139503709
1139180400
1138489200

补充:Php教程,Php入门 
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,