PHP 日期相關處理,例如:獲取本月第一天及最後一天等
阿新 • • 發佈:2019-01-26
直接貼程式碼了
//時間相關
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);
}