如何将纽约时间转换为UTC时区

how to convert time in ny to utc zone

如何通过 php 将纽约时区的给定时间转换为 UTC 时区。我只会给出时间而不是日期(例如 12:30 am )。我想将给定时间转换为 UTC 时间,例如 ( 05:30 am ).

因为协调世界时 (UTC) 比美国纽约州纽约 (NY) 早 5 小时。因此,您只需添加 5 小时即可将纽约时间转换为 UTC,如下所示:

<?php
    $ny_time = "12:30 am";
    $utc_time = strtotime("+5 hours", strtotime($ny_time));
    echo date('h:i a', $utc_time); // output 05:30 am
?>

只需使用 PHP 的 gmdate() 函数代替

date_default_timezone_set('America/New_York');
echo $script_tz = date_default_timezone_get();
$ny_time = "12:30 am";
echo gmdate('h:i a',strtotime($ny_time));// 05:30 am

gmdate() is identical to the date() function except that the time returned is Greenwich Mean Time (GMT).

Demo