PHP:转换时间戳的时区

发布于 2024-12-11 19:59:08 字数 636 浏览 1 评论 0原文

我在使用 Zend Framework 将时间戳(UTC 日期时间)转换为另一个时区时遇到问题。我的默认时区是欧洲/巴黎,

$timestamp = 1319530421;
$date = new Zend_Date();
$date->setTimezone('UTC');
$date->set($timestamp, Zend_Date::TIMESTAMP);
echo $date->get(Zend_Date::W3C).' - '.$date->getTimezone().'<br />';
$date->setTimezone('Europe/Paris');
echo $date->get(Zend_Date::W3C).' - '.$date->getTimezone().'<br />';

它会回显,

2011-10-25T08:13:41+00:00 - UTC
2011-10-25T10:13:41+02:00 - Europe/Paris

但它是错误的,因为该时间戳是

2011-10-25T10:13:41+00:00 - UTC

我做错了什么?谢谢

I have issues converting a timestamp, which is a UTC datetime, to another timezone using Zend Framework. My default timezone is Europe/Paris

$timestamp = 1319530421;
$date = new Zend_Date();
$date->setTimezone('UTC');
$date->set($timestamp, Zend_Date::TIMESTAMP);
echo $date->get(Zend_Date::W3C).' - '.$date->getTimezone().'<br />';
$date->setTimezone('Europe/Paris');
echo $date->get(Zend_Date::W3C).' - '.$date->getTimezone().'<br />';

which echoes

2011-10-25T08:13:41+00:00 - UTC
2011-10-25T10:13:41+02:00 - Europe/Paris

but it's wrong because that timestamp is

2011-10-25T10:13:41+00:00 - UTC

What am I doing wrong? Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酒绊 2024-12-18 19:59:08

您的示例中的时间戳是错误的。它的日期是:

date_default_timezone_set('UTC');

$timestamp = 1319530421;

echo date('c e', $timestamp); # 2011-10-25T08:13:41+00:00 UTC

所以你的例子都是正确的,只是你的期望不是。

You're wrong about the timestamp in your example. It's date is:

date_default_timezone_set('UTC');

$timestamp = 1319530421;

echo date('c e', $timestamp); # 2011-10-25T08:13:41+00:00 UTC

So it's all correct with your example, just your expectation isn't.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文