Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何通过 php 将 NY 区的给定时间转换为 UTC 区。我只会给出时间而不是日期(例如上午 12:30)。我想将给定时间转换为 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 ?>
只需使用gmdate()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()与date()函数相同,只是返回的时间是格林威治标准时间 (GMT)。
date()
演示