//时间相关
public function timeinfo(){
//获取今天0点-24点时间戳
$today = strtotime(date('Y-m-d', time()));
$todayend = $today + 24 * 60 * 60;
//获取本周第一天及最后一天
$weekfirst=strtotime(date('Y-m-d', strtotime('this week')));
$weeklast=strtotime(date('Y-m-d', strtotime('last day next week')));
//3.获取当天年份、月份、日及天数.
echo " 本月共有:".date("t")."天";
echo " 当前年份".date('Y');
echo " 当前月份".date('m');
echo " 当前几号".date('d');
//1.获取上个月第一天及最后一天.
echo date('Y-m-01', strtotime('-1 month'));
echo "<br/>";
echo date('Y-m-t', strtotime('-1 month'));
//2016-08-10这天 2个月后的日期
echo date("Y-m-d",strtotime("+2 month",strtotime("2016-08-10")));
//获取3 年、月、日 后的日期
echo date("Y-m-d",strtotime("+3 year",time()));
echo date("Y-m-d",strtotime("+3 month",time()));
echo date("Y-m-d",strtotime("+3 day",time()));
}
//获取当月第一天和最后一天
function getthemonth($date)
{
$firstday = date('Y-m-01', strtotime(date('Y-m-d')));
$lastday = date('Y-m-d', strtotime("$firstday +1 month -1 day"));
return array($firstday,$lastday);
}
本文详细介绍了使用PHP进行时间与日期的操作方法,包括获取今日、本周、本月的时间范围,计算特定日期前后的时间,以及如何获取当前的年、月、日等信息。通过具体代码示例,展示了如何利用PHP内置的strtotime和date函数实现日期的加减和格式化。
2513

被折叠的 条评论
为什么被折叠?



