Ⅰ php 下个月起始结束日期
$now = time();
$now_m = date("m", $now);
$next_line = $now + 28 * 60 * 60 * 24 - 1;
if(date("m", $next_line ) == $now_m ){
$first = date("Ymd", strtotime(date("Y-m-1", $next_line )));
$last = date("Ymd", strtotime(date("Y-m-28", $next_line )));
}else if(date("m", $next_line + 60 * 60 * 24 ) == $now_m){
$first = date("Ymd", strtotime(date("Y-m-1", $next_line + 60 * 60 * 24 )));
$last = date("Ymd", strtotime(date("Y-m-29", $next_line + 60 * 60 * 24 )));
}else if(date("m", $next_line + 60 * 60 * 24 * 2 ) == $now_m){
$first = date("Ymd", strtotime(date("Y-m-1", $next_line + 60 * 60 * 24 * 2 )));
$last = date("Ymd", strtotime(date("Y-m-30", $next_line + 60 * 60 * 24 * 2 )));
}else if(date("m", $next_line + 60 * 60 * 24 * 3 ) == $now_m){
$first = date("Ymd", strtotime(date("Y-m-1", $next_line + 60 * 60 * 24 * 3 )));
$last = date("Ymd", strtotime(date("Y-m-31", $next_line + 60 * 60 * 24 * 3 )));
}
这里为了演示所以直接把那些相乘计算分开写了,写到程序里时建议直接写结果,减少程序执行时间,这个程序可以封成一个方法,传入一个时间戳就可以获得指定时间的下个月的头天和最后一天了。
Ⅱ php 怎样获取本月最后一天的时间
使用time()函数先返回当前的时间戳秒数,然后+上本月剩余的x天*24*60*60
echo date("Y年-m月-d日-N,H点:i分:s秒",time()+(x*24*60*60));
Ⅲ php中如何获取最近六个月每个月的起始时间和结束时间
你要实现的是不是当前月份和当前月份往前5个月,每个月的第一天是几号号最后一天是几号?如果是的话,我写了一个 能实现你的需求。你的问题让我好纠结。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$currentTime = time();
$cyear = floor(date("Y",$currentTime));
$cMonth = floor(date("m",$currentTime));
for($i=0;$i<6;$i++){
$nMonth = $cMonth-$i;
$cyear = $nMonth == 0 ? ($cyear-1) : $cyear;
$nMonth = $nMonth <= 0 ? 12+$nMonth : $nMonth;
$date = $cyear."-".$nMonth."-1";
$firstday = date('Y-m-01', strtotime($date));
$lastday = date('Y-m-t', strtotime($date));
echo $cyear."年".$nMonth."月";
echo "第一天:".$firstday;
echo "最后一天:".$lastday,"";
}
Ⅳ php求当前季度的第一天和最后一天
$date = getdate();
$month = $date['mon']; //当前第几个月
$year = $date['year']; //但前的年份
$strart = floor($month/3) * 3; //单季第一个月
$strart = mktime(0,0,0,$start,1,$year); //当季第一天的时间戳
$end = mktime(0,0,0,$start+3,1,$year); //当季最后一天的时间戳
Ⅳ PHP DATE 如何取得当月的第一天和最后一天
本文实例讲述了PHP获取指定月份第一天和最后一天的方法。分享给大家供大家参考。具体如下:
复制代码 代码如下:$date = date(time());
$start_date = date('Y-m-d', mktime(00, 00, 00, date('m', strtotime($date))+1, 01));
$end_date = date('Y-m-d', mktime(23, 59, 59, date('m', strtotime($date))+2, 00));
希望本文所述对大家的php程序设计有所帮助。
Ⅵ 本年的第一天和最后一天,用PHP怎么得到
$BeginDate=date('Y-m-01', strtotime(date("Y-m-d"))); 获取当前月份第一天
echo $BeginDate;
echo date('Y-m-d', strtotime("$BeginDate +1 month -1 day")); 加一个月减去一天。
-----------------------------------
function getthemonth($date)
{
$firstday = date('Y-m-01', strtotime($date));
$lastday = date('Y-m-d', strtotime("$firstday +1 month -1 day"));
return array($firstday, $lastday);
}
Ⅶ php取某年某月的最后一天的时间戳怎么取,知道年月,不知到日
先取下一个月1号的日期,然后再减1天即可:
function get_last_day($year, $month) {
$t = mktime(0, 0, 0, $month + 1, 1, $year);
$t = $t - 60 * 60 * 24;
return $t;
}
Ⅷ php获取当年的每个月的第一天和最后一天时间戳的函数
/**
* 获取指定月份的第一天开始和最后一天结束的时间戳
*
* @param int $y 年份 $m 月份
* @return array(本月开始时间,本月结束时间)
*/
function mFristAndLast($y="",$m=""){
if($y=="") $y=date("Y");
if($m=="") $m=date("m");
$m=sprintf("%02d",intval($m));
$y=str_pad(intval($y),4,"0",STR_PAD_RIGHT);
$m>12||$m<1?$m=1:$m=$m;
$firstday=strtotime($y.$m."01000000");
$firstdaystr=date("Y-m-01",$firstday);
$lastday = strtotime(date('Y-m-d 23:59:59', strtotime("$firstdaystr +1 month -1 day")));
return array("firstday"=>$firstday,"lastday"=>$lastday);
}
Ⅸ php获取当月天数及当月第一天及最后一天、上月第一天及最后一天实现方法是什么
date('Y-m-01', strtotime('-1 month')); //上个月第一天
date('Y-m-t', strtotime('-1 month')); //上个月最后一天
$BeginDate=date('Y-m-01', strtotime(date("Y-m-d"))); //当月第一天
date('Y-m-d', strtotime("$BeginDate +1 month -1 day")); //当月最后一天