【问题标题】:How to convert string into timezone aware date如何将字符串转换为时区感知日期
【发布时间】:2020-08-28 15:28:54
【问题描述】:

你好,我有一个字符串2020-08-19 13:04:53。我知道这个时间是Sydney, Australia时间。但是,我需要将此时间转换为New York, America 时间作为日期对象。我该怎么做?

date_default_timezone_set("Australia/Sydney");
$time = '2020-08-19 13:04:53';
$date = date('Y-m-d H:i:s', $time);

【问题讨论】:

    标签: php date datetime strtotime


    【解决方案1】:

    我会尝试类似的东西

    <?php
    $date = new DateTime('2020-08-19 13:04:53', new DateTimeZone('Australia/Sydney'));
    echo $date->format('Y-m-d H:i:s');
    // Output: 2020-08-19 13:04:53
    
    $date->setTimezone(new DateTimeZone('America/New_York'));
    echo $date->format('Y-m-d H:i:s');
    // Output: 2020-08-18 23:04:53
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-14
      • 1970-01-01
      • 2017-01-03
      • 2020-01-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多