2017-01-15 4 views
0

Ich versuche, die aktuelle, die nächste und die nach dem nächsten Monat von PHP zu bekommen.PHP nächsten Monat Ausgabe

Dies ist meine aktuelle 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))); 

Der Name des Monats in Deutsch sein sollte, also verwende ich setlocale(LC_TIME, "de_DE.utf8");.

Die Ausgabe ist: Januar (Januar), Januar (Januar), Februar (Februar). Ich kann das Problem nicht herausfinden.

+0

überprüfen Sie dies. http://stackoverflow.com/questions/21661218/php-cant-get-date-in-german-language –

+0

Hinweis: Undefinierte Variable: Monat in ...... – RiggsFolly

+0

Wo ist '$ Monat' und '$ Jahr kommen aus – RiggsFolly

Antwort

0

Verwendung dieses setlocale (LC_TIME,"de_DE"); es funktioniert

<?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))); 

?> 

Ausgang

output picture

+0

Yay, wenn Sie '$ Monat' ignorieren und '$ Jahr' es funktioniert ??? !!! – RiggsFolly

+0

statt $ Monat & $ Jahr habe ich Normalwert 2017 für Jahr & 1 für Monat – Priyanka

0

ich von strtotime wegzubewegen vorschlagen und die PHP-datetime-Klasse verwenden.

$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 

Aktueller Monat ist Januar. Dieser Ausgang ist "Februar März"

Verwandte Themen