php获取当前月月初至月末的时间戳,上个月月初至月末的时间戳


当前月

<?php
$thismonth = date('m');
$thisyear  = date('Y');
$startDay = $thisyear . '-' . $thismonth . '-1';
$endDay   = $thisyear . '-' . $thismonth . '-' . date('t', strtotime($startDay));
$b_time       = strtotime($startDay);
$e_time       = strtotime($endDay);

 

上一月

<?php
$thismonth = date('m');
$thisyear  = date('Y');
if ($thismonth == 1) {
    $lastmonth = 12;
    $lastyear  = $thisyear - 1;
} else {
    $lastmonth = $thismonth - 1;
    $lastyear  = $thisyear;
}
$lastStartDay = $lastyear . '-' . $lastmonth . '-1';
$lastEndDay   = $lastyear . '-' . $lastmonth . '-' . date('t', strtotime($lastStartDay));
$b_time = strtotime($lastStartDay);
$e_time = strtotime($lastEndDay);

这里对关键的就是date函数中的t,它是用来获取当前月所含天数的,28天,29天,30天,31天。含有多少天,月底就是多少号。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM