简体   繁体   English

PHP添加天到strftime

[英]php add days to strftime

I need to print the Italian time from now to 30 days in this format 2013-03-11#11 Mar | Mon 我需要以这种格式打印从现在到30天的意大利时间2013-03-11#11 Mar | Mon 2013-03-11#11 Mar | Mon

I've found that the Date function don't return the italian translation so I'm using strftime . 我发现Date函数不会返回意大利语翻译,因此我正在使用strftime

but how can I add days to 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" );
    }

You can use this : 您可以使用:

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

This will display the month and day. 这将显示月份和日期。

This code seems to solve your problem: 这段代码似乎可以解决您的问题:

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>";
}

The problem you were having is that, strftime, was using the default date, which is today. 您遇到的问题是,strftime使用的是默认日期,即今天。 Looking at the documentation, http://php.net/manual/en/function.strftime.php , you can specify a timestamp for it to use instead, which is your future date (now +$i), as the second parameter. 查看文档http://php.net/manual/en/function.strftime.php ,您可以指定一个时间戳以供使用,它是您的未来日期(现在为+ $ i),作为第二个参数。

Enjoy! 请享用!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM