gpt4 book ai didi

php - 将事件添加到 Google 日历时的时差

转载 作者:可可西里 更新时间:2023-10-31 23:42:54 24 4
gpt4 key购买 nike

我有用于将给定 mailid 的事件添加到 Google Calender 的代码。

问题是,当我尝试添加事件时存在时差问题。

例如,如果我将以下内容添加到日历 03/21/2012 8:00AM 在网络上查看的日历条目中的时间设置为 17:30.

这是我的代码:

$gmail = 'mail@gmail.com';
$gpwd = '1233';
$datetime1 = strtotime('03/21/2012 8:00AM');
$date1 = date("Y-m-d", $datetime1);
$idg = add_to_calendernow1($gmail,$gpwd,$id,$date1,$datetime1);

function add_to_calendernow1($gmail,$gpwd,$ticket,$date,$timestamp){
if($gmail){
/* Change the below path with correct path class1.php and class2.php are in the includes directory */
include('includes/class1.php');
include('includes/class2.php');
$email = $gmail;
$password = $gpwd;
$altEmail = $gmail;
$login = new GoogleClientLogin($email, $password, GoogleClientLogin::$CALENDAR_SERVICE, APP_NAME);
$cal = new GoogleCalendar($login);
$cal->altEmail = $altEmail;
$content = "Ticket #".$ticket." scheduled now";
$entryData = $cal->addEvent(array(
"title"=> "Ticket #".$ticket." Scehduled An Item",
"content"=> $content,
"where"=> "",
"startTime"=> $timestamp,
"endTime"=> $timestamp
));
$id_now = explode('feeds/',$entryData['id']);
$sec_id = $id_now[1];
$id_id = explode('/',$sec_id);
return $id_id[0];
}
}

GoogleClientLogin 和 GoogleCalendar 类来自这篇博文:

http://mark.biek.org/blog/2010/07/addingdeleting-events-with-the-google-calendar-api/

有没有人知道可能导致这种情况的原因?

Google 日历的时区设置为东部标准时间,服务器位于美国。

我是否需要在我的代码中做一些其他事情来确保正确地传递时间?

最佳答案

你没有在你的例子中的任何地方设置时区,所以我猜你的时区设置是错误的,这意味着 PHP 可能使用默认设置,这可能是任何东西。

尝试使用 date_default_timezone_set() 设置时区

关于php - 将事件添加到 Google 日历时的时差,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9698759/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com