1

我需要以这种格式打印从现在到 30 天的意大利时间2013-03-11#11 Mar | Mon

我发现 Date 函数不返回意大利语翻译,所以我正在使用strftime

但是我怎样才能给strftime添加天数?

setlocale(LC_ALL, 'it_IT');
for($i=0; $i<30; $i++){
    echo $date = date("Y-m-d", strtotime('now + '.$i.' days'));
    echo " # ";
    echo $date_string = strftime("%d %b | %a" );
    }
4

2 回答 2

2

此代码似乎可以解决您的问题:

setlocale(LC_ALL, 'it_IT');
for($i=0; $i<30; $i++){
    echo $date = date("Y-m-d", strtotime('now + '.$i.' days'));
    echo " # ";
    echo $date_string = strftime( "%d %b | %a", strtotime('now + '.$i.' days') ) . "<br>";
}

您遇到的问题是 strftime 使用的是默认日期,即今天。查看文档http://php.net/manual/en/function.strftime.php,您可以指定一个时间戳来代替它使用,这是您的未来日期(现在 +$i),作为第二个参数.

享受!

于 2013-03-11T11:15:17.533 回答
1

你可以使用这个:

strftime("%d %b | %a",strtotime($date))

这将显示月份和日期。

于 2013-03-11T11:12:09.487 回答