dongzhen7108 2014-04-29 13:22
浏览 62
已采纳

Outlook Calendar API自行增加小时数

I am working with PHP and Outlook Calendar REST API, I am able to create the events just fine except that the date I give API to create an events is getting incremented by 11 hours and something is wrong with end_date also, for example if i am telling the API to create the event from 2014-03-31T15:00:00-0000 to 2014-03-31T16:00:00-0000 it ends up creating the event from 2014-04-01T02:00:00+1100 to 2014-04-01T02:30:00+1100

This is what my API URL looks like

https://apis.live.net/v5.0/9898ef90931244e8/events?name=testing_event&description=event_description&start_time=2014-03-31T15:00:00-0000&end_time=2014-03-31T16:00:00-0000&access_token=token-goes-here&method=POST

if I remove the -0000 at the end, i get the following error

{
   "error": {
      "code": "request_parameter_invalid", 
      "message": "The value of input parameter 'start_time' isn't valid. The expected formats for this parameter are the following: '1970-01-01T00:00:00Z', '1970-01-01T00:00:00.000Z', '1970-01-01 00:00:00Z'. In all cases, 'Z' is interchangeable with a time zone offset of the form: '+00:00', '-00:00', '+0000' or '-0000'."
   }
}

I will really appreciate any help as I have spent days trying to fix this and I am pretty much out of all ideas..

  • 写回答

1条回答 默认 最新

  • duanjie6912 2014-04-29 17:32
    关注

    A while ago I posted this question at MSDN Forum and forgot about it, today i visited the question and this is the reply I got from Outlook team explaining how to understand UTC timezone, I hope this helps someone out there stuck at the same problem and I wish they included this in their documentation. This fixed the problem I was having


    *The ISO 8601 format for dates can be a bit confusing. What you're seeing in your response is actually correct. The calendar service takes your date and maps it to the time zone of the user.

    "2014-03-31T15:00:00-0000" means 3 PM on March 31, 2014, with an adjustment of 0 hours and 0 minutes to translate to UTC time. In other words, this basically IS UTC time. The calendar service then translates this into the local time zone of the user for whom you are creating the event. "2014-04-01T02:00:00+1100" means 2 AM on April 1, 2014, for whatever time zone your user is in. To translate back to UTC, you need to SUBTRACT the offset from the local time. So 2 AM, April 1, 2014 in your time maps to 11 hours earlier UTC, which is 3 PM March 31, 2014 (what you entered).

    If you're using Z, that means that you are essentially specifying a UTC time. So to get the desired time for your event you need to take your desired time and figure out what the corresponding UTC time is. So if the UTC offset of your user is +1100 you would need to subtract that offset from the local time of your event to calculate the UTC time. In your case I believe this would be 2014-03-31T04:00:00Z. This is actually something that's best left to code instead of trying to figure out how to do yourself. If you take a look at the "Creating Calendar Events" sample at http://isdk.dev.live.com it shows you how to do this in JavaScript - maybe there's a PHP equivalent.*


    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗
  • ¥15 钢筋实图交点识别,机器视觉代码
  • ¥15 如何在Linux系统中,但是在window系统上idea里面可以正常运行?(相关搜索:jar包)
  • ¥50 400g qsfp 光模块iphy方案
  • ¥15 两块ADC0804用proteus仿真时,出现异常
  • ¥15 关于风控系统,如何去选择
  • ¥15 这款软件是什么?需要能满足我的需求
  • ¥15 SpringSecurityOauth2登陆前后request不一致
  • ¥15 禅道二次开发编辑版本,上传不了发行包