‘壹’ 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就行了。