简体   繁体   English

PHP 时间戳慢一小时

[英]PHP timestamp an hour slow

I am working on an ancient system written in vanilla PHP.我正在研究一个用普通 PHP 编写的古老系统。

I am having some time conversion issues.我有一些时间转换问题。

In the below example, I an expecting both the timestamp and the "pretty date" to reflect one another:在下面的示例中,我希望时间戳和“漂亮日期”相互反映:

<?php
date_default_timezone_set( 'Europe/London' );

$timestamp = 1509062400; //Friday, October 27, 2017 12:00:00 AM

$date = new DateTime();
$date->setTimezone( new DateTimeZone( 'Europe/London' ) );
$date->setTimestamp( $timestamp + 3601 );
$date->setTime( 0, 0 );

echo $date->getTimestamp();
echo '<br/>';
echo $date->format( 'Y-m-d H:i:s' );

However, when running this script on the server, the result is the following:但是,在服务器上运行此脚本时,结果如下:

Timestamp: 1509058800
Pretty Date: 2017-10-27 00:00:00

The pretty date represents 27th Oct 00:00, but the timestamp (according to epochconvertor ) represents 26th Oct 23:00.漂亮的日期代表 10 月 27 日 00:00,但时间戳(根据epochconvertor )代表 10 月 26 日 23:00。

I am not sure why the timestamp is an hour slow.我不确定为什么时间戳慢一个小时。 Can anyone help?任何人都可以帮忙吗?

If you're in London, then your timestamp is likely in British Summer Time.如果您在伦敦,那么您的时间戳很可能是英国夏令时。 The epoch is going to be in GMT.纪元将在格林威治标准时间。 BST is one hour ahead of GMT. BST 比 GMT 早一小时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM