dongxi8297 2019-05-02 03:33
浏览 54

如何在strtotime中更改时区?

Just to sum up here is my code:

echo @date('h:i A e', @strtotime($db_order_data['DeliveryDate'])); ?> on <?= @date('d M Y', @strtotime($db_order_data['DeliveryDate']));

How can I change the timezone of the specific deliverydate?

Note: I tried to add define('TIMEZONE', 'Pacific/Taipei'); on the topmost php but still did not work. Any help woud be appreciated. Thanks.

Edit: The time itself is the one that I need to change. Including the timezone. Sorry for my bad english.

  • 写回答

2条回答 默认 最新

  • douzhi3667 2019-05-02 03:50
    关注

    strtotime() will assume the PHP default timezone (set via php.ini or date_default_timezone_set()) unless your date string contains a timezone.

    Fiddling with global settings at runtime for this is not really best practice. You might be better off using the DateTime classes for this.

    $dt = new \DateTime($db_order_data['DeliveryDate'], new \DateTimeZone('Pacific/Taipei'));
    echo $dt->format('h:i A e') . " on " . $dt->format('d M Y');
    
    评论

报告相同问题?