PHP制作时间变量?5小时然后回复它?

Ris*_*shi 1 php time date

只是一个简单的问题,我怎样才能将以下日期/时间变量编辑为PLUS(+)小时数5,在美国时间,我需要将所有内容转换为英国时间.

$tme = date('H:i : d F Y');

有任何想法吗...?

Mad*_*iha 6

使用DateTime对象,它更健壮,并且会让您减少头痛:

$time = new DateTime("now", new DateTimeZone("America/New_York"));
$time->setTimezone(new DateTimeZone("Europe/London"));

echo $time->format("H:i:s Y-m-d");
Run Code Online (Sandbox Code Playgroud)

另请注意,通过这种方式,您可以处理奇怪的时区相关奇怪(例如某些时区在不同日期发生变化,一些时间依赖于年份等)而无需进行任何计算,DateTimeZone对象为您执行:-)