strtotime
(PHP 3>= 3.0.12, PHP 4 )strtotime -- 将任何英文文本的日期时间描述解析为 UNIX 时间戳
说明
int strtotime ( string time [, int now])
本函数预期接受一个包含英文日期格式的字符串并尝试将其解析为 UNIX 时间戳。如果 time 的格式是绝对时间则 now 参数不起作用。如果 time 的格式是相对时间则其所相对的时间由 now 提供,或者如果未提供 now 参数时用当前时间。失败时返回 -1。 因为 strtotime() 的行为是依照 GNU 日期语法的,因此请看看 GNU 手册中的 Date Input Formats。这里记述了 time 参数的合法语法。 例子 1. strtotime() 例子<?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);
}
?>
注: 有效的时间戳典型范围是从格林威治时间 1901 年 12 月 13 日 星期五 20:45:54 到 2038年 1 月 19 日 星期二 03:14:07。(该日期根据 32 位有符号整数的最小值和最大值而来。)
(PHP 3>= 3.0.12, PHP 4 )strtotime -- 将任何英文文本的日期时间描述解析为 UNIX 时间戳
说明
int strtotime ( string time [, int now])
本函数预期接受一个包含英文日期格式的字符串并尝试将其解析为 UNIX 时间戳。如果 time 的格式是绝对时间则 now 参数不起作用。如果 time 的格式是相对时间则其所相对的时间由 now 提供,或者如果未提供 now 参数时用当前时间。失败时返回 -1。 因为 strtotime() 的行为是依照 GNU 日期语法的,因此请看看 GNU 手册中的 Date Input Formats。这里记述了 time 参数的合法语法。 例子 1. strtotime() 例子<?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);
}
?>
注: 有效的时间戳典型范围是从格林威治时间 1901 年 12 月 13 日 星期五 20:45:54 到 2038年 1 月 19 日 星期二 03:14:07。(该日期根据 32 位有符号整数的最小值和最大值而来。)
解决方案 »
- 关于iframe的问题
- 怎么用PHP创建MYSQL的存储过程
- php+js 遍历树出现乱码
- 有一数组中的值是按天显示的,如何改为按月显示的?
- 各位大侠,怎样 解析接收到的HTTP邮件中的字段?十万火急,万分感谢。
- 跟大家请教一个关于php+mysql字符编码问题,谢谢
- 如何利用PHP会话显示出当前在线的用户
- 下载文件隐藏
- Apache中如何设置某个虚拟主机不可使用PHP?
- php错误提示: mysql_fetch_row(): supplied argument is not a valid MySQL
- [求助]关于正则表达式的问题:
- 急问:一数组问题... 急..............thanks............................
(PHP 3, PHP 4 )mktime -- 取得一个日期的 UNIX 时间戳
说明
int mktime ( int hour, int minute, int second, int month, int day, int year [, int is_dst])
警告:注意参数的奇怪顺序,这和标准的 UNIX mktime() 调用中的参数顺序不同。在脚本经常会混淆这些值而出错。 根据给出的参数返回 Unix 时间戳。时间戳是一个长整数,包含了从 Unix 新纪元(1970 年 1 月 1 日)到给定时间的秒数。
希望还能更进一步了解。
还要有date的用法及各个参数的作用。