date(format,timestamp)
- d - 月中的天 (01-31)
- m - 当前月,以数字计 (01-12)
- Y - 当前的年(四位数)
-
h 小时,12 小时格式,有前导零 01 到 12
H 小时,24 小时格式,有前导零 00 到 23
i 有前导零的分钟数 00 到 59>
s 秒数,有前导零 00 到 59>
在使用日期前一般要设置
date_default_timezone_set(时区)
中国为RPC。
date_default_timezone_set('PRC');
echo date('Y-m-d h:i:s' );
输出:2013-10-15 10:04:12。
int strtotime ( string $time
[, int $now
= time() ] )
将任何英文文本的日期时间描述解析为 Unix 时间戳
echo strtotime("now"), " "; echo strtotime("10 September 2000"), " "; echo strtotime("+1 day"), " "; echo strtotime("+1 week"), " "; echo strtotime("+1 week 2 days 4 hours 2 seconds"), " "; echo strtotime("next Thursday"), " "; echo strtotime("last Monday"), " ";
判断前一天后一天的代码:
date_default_timezone_set('PRC'); //默认时区 echo "今天:",date("Y-m-d",time()),"<br>"; echo "今天:",date("Y-m-d",strtotime("18 june 2008")),"<br>"; echo "昨天:",date("Y-m-d",strtotime("-1 day")), "<br>"; echo "明天:",date("Y-m-d",strtotime("+1 day")), "<br>"; echo "一周后:",date("Y-m-d",strtotime("+1 week")), "<br>"; echo "一周零两天四小时两秒后:",date("Y-m-d G:H:s",strtotime("+1 week 2 days 4 hours 2 seconds")), "<br>"; echo "下个星期四:",date("Y-m-d",strtotime("next Thursday")), "<br>"; echo "上个周一:".date("Y-m-d",strtotime("last Monday"))."<br>"; echo "一个月前:".date("Y-m-d",strtotime("last month"))."<br>"; echo "一个月后:".date("Y-m-d",strtotime("+1 month"))."<br>"; echo "十年后:".date("Y-m-d",strtotime("+10 year"))."<br>";
判断某个日期离今天还有多少天:
echo (strtotime('2013-10-17')-strtotime(date('Y-m-d')) )/86400;