2017-01-15 17 views
0

我試圖通過php獲取當前,下個月和下個月後。PHP得到下個月的問題

這是我目前的PHP:

setlocale(LC_TIME, "de_DE.utf8"); 
$thismonth = strftime("%B"); 
$nextmonth = strftime('%B', strtotime('+1 month', mktime(0, 0, 0, $month, 1, $year))); 
$overnextmonth = strftime('%B', strtotime('+2 month', mktime(0, 0, 0, $month, 1, $year))); 

月份名稱應該是德國人,所以我用setlocale(LC_TIME, "de_DE.utf8");。輸出是:Januar(一月),Januar(一月),Februar(二月)。我無法解決這個問題。

+0

檢查了這一點。 http://stackoverflow.com/questions/21661218/php-cant-get-date-in-german-language –

+0

注意:未定義的變量:month in ...... – RiggsFolly

+0

'$ month'和'$年'來自 – RiggsFolly

回答

0

使用這種setlocale (LC_TIME,"de_DE");它會工作

<?php 
setlocale (LC_TIME,"de_DE"); 
echo $thismonth = strftime("%B"); 
echo $nextmonth = strftime('%B', strtotime('+1 month', mktime(0, 0, 0, 1, 1, 2017))); 
echo $overnextmonth = strftime('%B', strtotime('+2 month', mktime(0, 0, 0, 2, 1, 2017))); 

?> 

輸出

output picture

+0

耶,如果你忽略'$月'和'$年'它的作品??? !!! – RiggsFolly

+0

而不是$ month&$ year我把正常值2017年和1月份 – Priyanka

0

我建議擺脫的strtotime路程,使用PHP DateTime類。

$date = new DateTime(); 
$date->add(new DateInterval('P1M')); // <-- adds 1 month to the current 
echo $date->format('F') . "\n"; // it's now January so it outputs February 
$date->add(new DateInterval('P1M')); 
echo $date->format('F') . "\n"; // adds one more (total 2) months from original 

當前月份是1月份。這個輸出將是「二月三月」