You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Microsoft Graph创建全天重复事件误生成多日事件

解决Microsoft Graph创建单日重复全天事件显示为2天的问题

问题场景

在用Microsoft Graph创建M365中的全年重复全天事件时碰到了这些问题:

  • 提交的JSON里事件本该只占4月1日一天,但实际显示为4月1日至4月2日的两天事件
  • 移除重复规则后,事件能正常显示为仅4月1日当天
  • 尝试把结束日期设为和开始日期相同,触发Graph错误提示must specify 24 hours;尝试添加时间并将结束日期设为开始日期后23小时59分,还是触发同样错误
  • 另外,从M365原生创建的同类事件导出的JSON中,开始日期符合预期,结束日期是开始日期加1天,但把这个导出的JSON传给Graph却不被接受

原请求JSON:

{
    "subject":  "Annual all day event",
    "isAllDay": true,
    "start":    {
        "dateTime": "2026-04-01",
        "timeZone": "UTC"
    },
    "end":  {
        "dateTime": "2026-04-02",
        "timeZone": "UTC"
    },
    "showAs":   "free",
    "recurrence":   {
        "pattern":  {
            "type": "absoluteYearly",
            "interval": 1,
            "dayOfMonth":   1,
            "month":    4
        },
        "range":    {
            "type": "noEnd",
            "startDate":    "2026-04-01",
            "recurrenceTimeZone":   "GMT Standard Time"
        }
    },
    "isOrganizer":  false,
    "organizer":    {
        "emailAddress": {
            "name": "test@domain.com",
            "address":  "test@domain.com"
        }
    },
    "body": {
        "contentType":  "text",
        "content":  "\r\n"
    }
}

解决方案

核心调整点

  1. 统一时区:确保事件的start/timeZone、end/timeZone和重复规则的recurrence.range.recurrenceTimeZone完全一致,避免时区转换导致日期偏移
  2. 遵循全天事件的结束日期规则:Graph要求全天事件的end.dateTime必须是start.dateTime的次日,这是内部逻辑的硬性要求,不用尝试改成同一天

修正后的JSON示例

{
    "subject": "Annual all day event",
    "isAllDay": true,
    "start": {
        "dateTime": "2026-04-01",
        "timeZone": "GMT Standard Time"
    },
    "end": {
        "dateTime": "2026-04-02",
        "timeZone": "GMT Standard Time"
    },
    "showAs": "free",
    "recurrence": {
        "pattern": {
            "type": "absoluteYearly",
            "interval": 1,
            "dayOfMonth": 1,
            "month": 4
        },
        "range": {
            "type": "noEnd",
            "startDate": "2026-04-01",
            "recurrenceTimeZone": "GMT Standard Time"
        }
    },
    "isOrganizer": false,
    "organizer": {
        "emailAddress": {
            "name": "test@domain.com",
            "address": "test@domain.com"
        }
    },
    "body": {
        "contentType": "text",
        "content": "\r\n"
    }
}

关键说明

  • 时区不统一是导致事件显示跨天的主要原因,原请求中事件用UTC时区,重复规则用GMT标准时间,两者转换后会出现日期差
  • 原生M365导出的JSON包含一些平台内部的隐含配置,直接复用会触发Graph的校验逻辑,需要手动调整时区等参数后再提交
  • 全天事件的结束日期设为次日是Graph的规范,只要时区统一,前端会正确显示为单日事件

内容的提问来源于stack exchange,提问作者Jeff McKay

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.11 10:36:06