문제

I have this piece of code:

<?php

    setlocale(LC_ALL,"es_ES");
    $contador = 1;
    $diaActual = time();

    while ($contador <= 7) {

        echo date("D j-n-Y", $diaActual)."<br><br>";
        $contador++;
        $diaActual = strtotime("+1 day", $diaActual);

    }


?>

Result:

Tue 13-5-2014

Wed 14-5-2014

Thu 15-5-2014

Fri 16-5-2014

Sat 17-5-2014

Sun 18-5-2014

Mon 19-5-2014

Why isn't working?

도움이 되었습니까?

해결책

From the manual about date()

To format dates in other languages, you should use the setlocale() and strftime() functions instead of date().

So use strftime():

print strftime("%a %d-%m-%Y");

To sum up always one day, just use a timestamp like:

for ($time = time(), $contador = 1;
     $contador <= 7;
     $contador++, $time = strtotime('+1 day', $time)) {
    print strftime("%a %d-%m-%Y", $time)."<br />\n";
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top