導航:首頁 > 編程語言 > php獲取月份第一天和最後一天

php獲取月份第一天和最後一天

發布時間:2022-09-03 13:40:08

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")); //當月最後一天

閱讀全文

與php獲取月份第一天和最後一天相關的資料

熱點內容
初次認識控制命令完整版 瀏覽:255
雙屏程序員 瀏覽:799
怎麼把兩個文件夾放到一個文件夾裡面 瀏覽:545
命令與征服大神宮 瀏覽:207
php發送簡訊驗證碼 瀏覽:505
前端伺服器如何接收http請求 瀏覽:796
程序員資質查詢 瀏覽:357
程序員被別人開除怎麼辦 瀏覽:888
解壓視頻看一下 瀏覽:129
android仿知乎日報 瀏覽:335
為什麼前端比安卓手機需求大 瀏覽:855
命令行執行關機命令 瀏覽:52
在學校心情不好怎麼解壓 瀏覽:116
我的世界基岩版伺服器怎麼讀取 瀏覽:161
快件命令 瀏覽:853
阿里雲06折伺服器能用嗎 瀏覽:421
h5個人中心源碼 瀏覽:221
下三角矩陣的壓縮存儲 瀏覽:922
招人用什麼app好用 瀏覽:722
飛行控制源碼 瀏覽:185