『壹』 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 如何計算指定時間,往後1個月的時間戳
int strtotime ( string $time [, int $now = time() ] )
strtotime 可以傳入第二個參數,用來表示參考時間,默認是當前時間,所以 strtotime('+1 month'); 才會計算出下個月的時間。
『叄』 在php中如何獲得未來時間
php獲取昨天、今天、明天、上周、本月、一年後、十年後的開始時間戳和結束時間戳:
//php獲取昨天日期
date("Y-m-d",strtotime("-1day"))
//php獲取明天日期
date("Y-m-d",strtotime("+1day"))
//php獲取一周後日期
date("Y-m-d",strtotime("+1week"))
//php獲取一周零兩天四小時兩秒後時間
date("Y-m-dG:H:s",strtotime("+1week2days4hours2seconds"))
//php獲取下個星期四日期
date("Y-m-d",strtotime("nextThursday"))
//php獲取上個周一日期
date("Y-m-d",strtotime("lastMonday"))
//php獲取一個月前日期
date("Y-m-d",strtotime("lastmonth"))
//php獲取一個月後日期
date("Y-m-d",strtotime("+1month"))
//php獲取十年後日期
date("Y-m-d",strtotime("+10year"))
//php獲取今天起止時間戳
mktime(0,0,0,date('m'),date('d'),date('Y'));
mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
//php獲取昨天起止時間戳
mktime(0,0,0,date('m'),date('d')-1,date('Y'));
mktime(0,0,0,date('m'),date('d'),date('Y'))-1;
//php獲取上周起止時間戳
mktime(0,0,0,date('m'),date('d')-date('w')+1-7,date('Y'));
mktime(23,59,59,date('m'),date('d')-date('w')+7-7,date('Y'));
//php獲取本月起止時間戳
mktime(0,0,0,date('m'),1,date('Y'));
mktime(23,59,59,date('m'),date('t'),date('Y'));
『肆』 php 如何判斷下一個月 幾號
用php的date函數去判斷
獲取年:date('Y');
獲取月:date('m');
獲取日:date('d');
獲取時:date('H');
獲取分:date('i');
獲取秒:date('s');
例如,判斷今天是不是10月16日
<?php
if(date('m')==10&&date('d')==16){
echo'今天是10月16日';
}else{
echo'今天不是10月16日';
}
?>
『伍』 php 怎麼得到當前時間1個月後時間
<?php
$date_two_ms = date('Y-m-d',strtotime('next month'));
?>
還可以這樣,你隨便選擇一個使用就可以了
<?php
$now = time(); //獲取當前的時間戳
$date_two_ms = date('Y-m-d',$now+3600*24*30); //這里使用了30天 你也可以換成 31天什麼的
?>
『陸』 PHP怎麼獲得一天,一周,一個月的起始和結束的時間戳求高人指點
PHP獲取開始和結束時間
//當前時間
$start
=
strtotime(date('Y-m-d
H:i:s'));
//時長,時間長度(秒為單位,例子中為120秒,2分鍾後,實際時間可自行修改或程序計算得出)
//如果是1周後,則為$start
+
(7
*
24
*
60
*
60);
$long
=
$start
+
120
//結束時間
$end
=
date('Y-m-d
H:i:s',
$long);
php可以用函數time()來獲取Unix
時間戳,但是只能獲取當前的,不能填入參數計算
『柒』 如何獲取當前月份的下一月的第一天 php
date_default_timezone_set("PRC");
functiongetNextMonthDays($date){
$timestamp=strtotime($date);
$arr=getdate($timestamp);
if($arr['mon']==12){
$year=$arr['year']+1;
$month=$arr['mon']-11;
$firstday=$year.'-0'.$month.'-01';
}else{
$firstday=date('Y-m-01',strtotime(date('Y',$timestamp).'-'.(date('m',$timestamp)+1).'-01'));
}
return$firstday;
}
$date=date('Y-m-d');
echogetNextMonthDays($date);
『捌』 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中使用mktime() 如何獲取上一月昨天的時間,今天的時間,明天的時間;
如果一個月固定30天,那真的很好辦,直接當前 時間戳-30*86400 就是上一月今天的時間戳了,加減一次86400就是加減一天。
如果今天幾號要對應上一月幾號,我就提一些注意點吧,當前月份減1和加1當然就是上一個月和下一個月,不過注意要12月和1月的判斷,還有如果今天3月30號,上一個月也沒30號,這些還要看你自己想怎麼處理。只要拿到正確的日期,傳入mktime就拿到時間了,至於昨天和明天,一樣加減一次86400就行了。