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 位有符号整数的最小值和最大值而来。)
(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的用法及各个参数的作用。