php – 向Google日历添加活动时的时差

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – 向Google日历添加活动时的时差脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我有代码用于为给定的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日历的时区设置为东部标准时间,服务器位于美国.

我的代码是否还需@L_406_19@其他事情以确保时间得到正确执行?

解决方法

你没有在你拥有的示例中的任何地方设置时区,所以我猜你的时区设置是错误的,这意味着PHP可能正在使用认设置,可能几乎任何事情.

尝试使用date_default_timezone_set()设置时区

脚本宝典总结

以上是脚本宝典为你收集整理的php – 向Google日历添加活动时的时差全部内容,希望文章能够帮你解决php – 向Google日历添加活动时的时差所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。