简体   繁体   中英

PHP timestamp an hour slow

I am working on an ancient system written in vanilla 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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