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 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料