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