php date strtotime +3天给我一个从开始2到3天的日期?

时间:2012-09-22 14:39:26

标签: php time

我需要从日期转换并添加+3天。当我使用strtotime(“最后结婚+3天”);它给了我2到3天的日期。它在我的服务器和互联网上不起作用我用键盘测试它:http://codepad.org/MhL77CVChttp://www.unixtimestamp.com/index.php。它给我的时间是从最后一个星期三开始的2到3天,也就是美国东部时间晚上7:00:00。我居住的地方是+1 Utc。我需要的是00:00的东西,我觉得有可能吗?我的客户对他的答案并不是很有帮助。他认为everthing在+1 UTC时区工作?

2 个答案:

答案 0 :(得分:1)

使用DateTime类将字符串转换为时间。第二个参数接受时区,使用DateTimeZone

$z = new DateTimeZone("Europe/Berlin");
$d = new DateTime("last wed +3 day", $z);
echo $d->format("d.m.Y H:i");
echo $d->format("U"); # or echo $d->getTimestamp(); on PHP > 5.3.0

DateTime::format()方法接受date()函数等格式。

答案 1 :(得分:0)

如果您需要转换时区,可以使用date_default_timezone_set()

    $date = new DateTime("last wed +3 day", new DateTimeZone('Europe/Rome')); 

    date_default_timezone_set('Europe/Rome'); 
    echo date("Y-m-d h:iA", $date->format('U')); 
    echo "<br/>";
    date_default_timezone_set('America/New_York'); 
    echo date("Y-m-d h:iA", $date->format('U')); 

您还可以通过在脚本开头设置正确的时区来解决问题