Friday, March 23, 2007

计算某月天数

function days_in_month($a_month, $a_year) {
return date('t', strtotime($a_year . '-' . $a_month . '-01'));
}
date :
t 给定月份所应有的天数 28 到 31

strtotime
(PHP 3 >= 3.0.12, PHP 4, PHP 5)
strtotime -- 将任何英文文本的日期时间描述解析为 Unix 时间戳
说明
int strtotime ( string time [, int now] )
本函数预期接受一个包含美国英语日期格式的字符串并尝试将其解析为 Unix 时间戳(自 January 1 1970 00:00:00 GMT 起的秒数),其值相对于 now 参数给出的时间,如果没有提供此参数则用系统当前时间。
本函数将使用 TZ 环境变量(如果有的话)来计算时间戳。自 PHP 5.1.0 起有更容易的方法来定义时区用于所有的日期/时间函数。此过程在 date_default_timezone_get() 函数页面中有说明。
注: 如果给定的年份是两位数字的格式,则其值 0-69 表示 2000-2069,70-100 表示 1970-2000。
参数
time
被解析的字符串,格式根据 GNU Date Input Formats 语法
now
用来计算返回值的时间戳
返回值
成功则返回时间戳,否则返回 FALSE。在 PHP 5.1.0 之前本函数在失败时返回 -1。

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";

No comments :