从PHP中删除一小时(FROM_UNIXTIME)

Could you please advice how to remove an hour from unixtime.

I have a unixtime and i need to remove an extra hour before converting to normal time. Could you please advice how to do this?

Also, is Unixtime affected by the GMT time changes?

Unix timestamps are measured in seconds, there are 3600 seconds in an hour (60 minutes, each with 60 seconds = 60*60 = 3600), so just subtract:

$timestamp = time();
$timestamp_less_one_hour = $timestamp - 3600;

You can also use strtotime to accomplish the same:

$timestamp_less_one_hour = strtotime('-1 hour', $timestamp);

Or if $timestamp is simply "now" you can call strtotime without the second parameter:

$timestamp_less_one_hour = strtotime('-1 hour'); // time() - 1 hour

So you seem to be looking for GMT time instead, the trouble is GMT can include Daylight Savings Time (DST), and the "GMT" date functions in PHP actually return UTC time, which has no concept of DST. Luckily you can detect if it's DST using PHP, and basically adjust appropriately.

Get UTC time using gmdate:

$utc_time = gmdate('U'); // return Unix seconds in UTC timezone

Detect if it's DST using I:

$is_dst = gmdate('I'); // 1 when it's DST, 0 otherwise

gmdate('U') will trail GMT time during DST by an hour, thus you need to give it +3600 seconds, or 1 hour when it's DST, so putting this together:

$gmt_time = gmdate('U') + (3600*gmdate('I'));