php中给定月份的下一个月和上一个月
可能重复:php中给定月份的下一个月和上一个月,php,date,Php,Date,可能重复: 我正在开发一个php的工作。在这里,我想得到给定月份的下一个月和上一个月,例如: $mth=“十二月” 我想展示下一个和上一个12月 提前感谢这应该可以: $date = new DateTime(); $date->modify('+ 1 month'); print $date->format("F"); // next $date->modify('- 2 month'); print $date->format("F"); // previousl
我正在开发一个php的工作。在这里,我想得到给定月份的下一个月和上一个月,例如:
$mth=“十二月”
我想展示下一个和上一个12月
提前感谢这应该可以:
$date = new DateTime();
$date->modify('+ 1 month');
print $date->format("F"); // next
$date->modify('- 2 month');
print $date->format("F"); // previously
这应该做到:
$date = new DateTime();
$date->modify('+ 1 month');
print $date->format("F"); // next
$date->modify('- 2 month');
print $date->format("F"); // previously
看看这个,这也是获取这些东西的一种方式
$mth="December";
$nxt = date('F',mktime(0,0,0,date("m", strtotime($mth))+2,null,null));
$pre = date('F',mktime(0,0,0,date("m", strtotime($mth))-0,null,null));
echo $pre.'-'.$mth.'-'.$nxt;
看看这个,这也是获取这些东西的一种方式
$mth="December";
$nxt = date('F',mktime(0,0,0,date("m", strtotime($mth))+2,null,null));
$pre = date('F',mktime(0,0,0,date("m", strtotime($mth))-0,null,null));
echo $pre.'-'.$mth.'-'.$nxt;