您的位置:首页 > 编程语言 > PHP开发

PHP 日期相关处理,例如:获取本月第一天及最后一天等

2017-05-12 11:55 513 查看
直接贴代码了

//时间相关
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
相关文章推荐