获取 UNIX 时间戳的正确小时数 [英] Get the correct hour for a UNIX timestamp

查看:26
本文介绍了获取 UNIX 时间戳的正确小时数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为这是一个愚蠢的问题,但似乎我找不到答案.

I think this is a stupid question, but seems that I cannot find the answer.

我有这个时间戳:1295598602.

I have this timestamp: 1295598602.

在我的 php 脚本中,我有:

In my php script I have:

$date = date('Y-m-d', 1295598602);$hour = date('H', 1295598602) .':00';

$date = date('Y-m-d', 1295598602); $hour = date('H', 1295598602) . ':00';

返回:

日期:2011-01-21
时间:03:00

Date: 2011-01-21
Hour: 03:00

现在我去了一个在线转换网站来测试这个.我使用了这个.但似乎对于这个时间戳值是

Now I went to an online conversion site to test this. I used this one. But it seems that for this timestamp value it is

2011 年 1 月 21 日星期五 08:30:02 GMT

Fri, 21 Jan 2011 08:30:02 GMT

现在,哪个是正确的?

推荐答案

使用正确的时区:

>> date_default_timezone_get();
'UTC'
>> date('Y-m-d h:i:s',1295598602);
'2011-01-21 08:30:02'
>> date_default_timezone_set('CET');
true
>> date('Y-m-d h:i:s',1295598602);
'2011-01-21 09:30:02'
>> date_default_timezone_set('UTC');
true
>> date('Y-m-d h:i:s',1295598602);
'2011-01-21 08:30:02'

这篇关于获取 UNIX 时间戳的正确小时数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆