php中的时区转换

发布于 2024-11-05 09:06:27 字数 728 浏览 5 评论 0原文

我在谷歌日历中的默认时区是(GMT-08:00)太平洋时间。现在我生成一个会议请求并邀请两个人。
1) 一个人的日历中的默认时区是 (GMT+05:30) 太平洋时间,并且他的电子邮件通过 Microsoft Exchange 服务器发送。
2) 其次,我邀请了一个使用默认时区的 Gmail 帐户的人时区为 (GMT+05:30)。
我查看的 ics 文件的 DTSTART 为 DTSTART:20110506T170000Z,它的意思就像
yyyymmdd T hhmmss 所以 gmail 中的时间是正确的。
但是第一个查看微软的人得到 DTSTART:20110506T070000Z 所以这里我的问题是如何转换时区以便两者都相同...

date_default_timezone_set($timezonename[0]->timzone_val); 
$meetingstamp = strtotime($meeting_date." ".$timezonename[0]->timzone_val);
$dtstart= gmdate("Ymd\This\Z",$meetingstamp);
$dtend= gmdate("Ymd\This\Z",$meetingstamp+$meeting_duration);
$todaystamp = gmdate("Ymd\This\Z");

这里我的时区是 America/Los_Angeles 那么我应该如何使用哪个函数来获得正确的计时...????

My defaulst timezone in google calendar is (GMT-08:00) Pacific Time. Now i generate a meeting request and invite two persons.
1) one person whose default timezone in his calendar is (GMT+05:30) Pacific Time and his email are coming through microsoft exchange server.
2) second i invite a person on gmail account who is having default timezone as (GMT+05:30).
the ics file which i view has DTSTART as DTSTART:20110506T170000Z it just means like
yyyymmdd T hhmmss so here time comes proper in gmail.
but the first person viewing microsoft gets DTSTART:20110506T070000Z so here my question is how to convert timezone so that both comes the same...

date_default_timezone_set($timezonename[0]->timzone_val); 
$meetingstamp = strtotime($meeting_date." ".$timezonename[0]->timzone_val);
$dtstart= gmdate("Ymd\This\Z",$meetingstamp);
$dtend= gmdate("Ymd\This\Z",$meetingstamp+$meeting_duration);
$todaystamp = gmdate("Ymd\This\Z");

here my timzone comes as America/Los_Angeles so how which function shall i use to get proper timings...????

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

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

发布评论

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

评论(1

不语却知心 2024-11-12 09:06:27
$start = new DateTime($meeting_date, new DateTimeZone($timezonename[0]->timzone_val);
$start->setTimezone(new DateTimeZone('UTC'));
$end   = clone $start;
$end->modify(sprintf('+ %d seconds', $meeting_duration));

echo $start->format('Ymd\THis\Z');
echo $end->format('Ymd\THis\Z');

顺便说一下,它应该是日期格式字符串中的大写 H,因为小写 h 代表我们的 12-hout-format。

EDIT 最后评论

$start = new DateTime('2011-05-07 10:00', new DateTimeZone('PDT'));
$start->setTimezone(new DateTimeZone('UTC'));
$end   = clone $start;
$end->modify(sprintf('+ %d seconds', 1*60*60));

echo $start->format('Ymd\THis\Z');
echo "\n";
echo $end->format('Ymd\THis\Z');

结果

20110507T170000Z
20110507T180000Z

之后这正是您想要获得的值。

$start = new DateTime($meeting_date, new DateTimeZone($timezonename[0]->timzone_val);
$start->setTimezone(new DateTimeZone('UTC'));
$end   = clone $start;
$end->modify(sprintf('+ %d seconds', $meeting_duration));

echo $start->format('Ymd\THis\Z');
echo $end->format('Ymd\THis\Z');

It should be an upper-case H in the date formatting string by the way, beacuse lower-case h represents ours in 12-hout-format.

EDIT after last comment

$start = new DateTime('2011-05-07 10:00', new DateTimeZone('PDT'));
$start->setTimezone(new DateTimeZone('UTC'));
$end   = clone $start;
$end->modify(sprintf('+ %d seconds', 1*60*60));

echo $start->format('Ymd\THis\Z');
echo "\n";
echo $end->format('Ymd\THis\Z');

results in

20110507T170000Z
20110507T180000Z

That are exactly the values you'd like to get.

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