php – 向Google日历添加活动时的时差
发布时间:2020-12-13 22:34:08 所属栏目:PHP教程 来源:网络整理
导读:我有代码用于为给定的mailid添加事件给Google Calender. 问题是,当我尝试添加事件时,存在时差问题. 例如,如果我将以下内容添加到日历03/21/2012上午8:00,则在Web上查看的日历条目中的时间将设置为17:30. 这是我的代码: $gmail = 'mail@gmail.com';$gpwd = '
我有代码用于为给定的mailid添加事件给Google Calender.
问题是,当我尝试添加事件时,存在时差问题. 例如,如果我将以下内容添加到日历03/21/2012上午8:00,则在Web上查看的日历条目中的时间将设置为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,$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()设置时区 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |