简体   繁体   English

c# 使用 Google.Apis.Calendar.v3 创建下个月每个工作日 30 分钟事件的会议

[英]c# using Google.Apis.Calendar.v3 create meeting for next month every weekday 30 min event

I want to create daily weekdays event for 30 minit.我想创建 30 分钟的每日工作日活动。 it seems there is something wrong in似乎有什么问题

Recurrence = new String[] { "RRULE:FREQ=MONTHLY;BYDAY=MO,TU,WE,TH,FR;UNTIL=" + nextmonthlastdayString + "T040000Z" },

I am not able to find solution tried many things.我无法找到解决方案尝试了很多事情。

 public async Task<ActionResult> NewEvent()
    {
        var credential = await GetCredentialForApiAsync();

        var initializer = new BaseClientService.Initializer()
        {
            HttpClientInitializer = credential,
            ApplicationName = "ASP.NET MVC5 Calendar Sample",
        };

        var service = new CalendarService(initializer);
        var today = DateTime.Now;
        var nextmonth = today.AddMonths(1).AddDays(-today.Day + 1);
        var nextmonthString = nextmonth.ToString("yyyyMMdd");
        var nxtmonthLastDate= DateTime.DaysInMonth(nextmonth.Year, nextmonth.Month);
        DateTime lastDayNextMonth = nextmonth.AddDays(-nextmonth.Day + nxtmonthLastDate);
        var nextmonthlastdayString = lastDayNextMonth.ToString("yyyyMMdd");


        var lastDayofMonthString = DateTime.DaysInMonth(nextmonth.Year, nextmonth.Month).ToString(nextmonth.Year + "" + nextmonth.Month + "" + nextmonth.Day);

        DateTime start = DateTime.Now;
        DateTime end = start + TimeSpan.FromMinutes(30);
        //start = DateTime.SpecifyKind(start, DateTimeKind.Local);
        //end = DateTime.SpecifyKind(end, DateTimeKind.Local);


        Event newEvent = new Event()
        {
            Summary = " Dealer Meeting",
            Location = "1600 Amphitheatre Parkway., Mountain View, CA 94043",
            Description = "A chance to learn more about Google APIs.",
         
            Start = new EventDateTime()
            {
                DateTime = nextmonth,
                TimeZone = "Asia/Kolkata",
            },
            End = new EventDateTime()
            {
                DateTime = lastDayNextMonth,
                TimeZone = "Asia/Kolkata",
            },

            //Recurrence = new String[] { "RRULE:FREQ=DAILY;COUNT=5" },

            //Recurrence = new String[] { "RRULE:FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR;UNTIL="+ nextmonth + "T040000Z" },
            Recurrence = new String[] { "RRULE:FREQ=MONTHLY;BYDAY=MO,TU,WE,TH,FR;UNTIL=" + nextmonthlastdayString + "T040000Z" },
            Attendees = new EventAttendee[] {
                new EventAttendee() { Email = "test@test.com" },
            },
            Reminders = new Event.RemindersData()
            {
                UseDefault = false,
                Overrides = new EventReminder[] {
                    new EventReminder() { Method = "email", Minutes = 24 * 60 },
                    new EventReminder() { Method = "sms", Minutes = 10 },
            }
            }
        };

        String calendarId = "primary";
        EventsResource.InsertRequest request = service.Events.Insert(newEvent, calendarId);
        Event createdEvent = request.Execute();
        return View();
    }

Your RRULE is correct, the problem is the end date您的 RRULE 是正确的,问题是end日期

As per documentation :根据文档

end结尾

The (exclusive) end time of the event.事件的(独占)结束时间。 For a recurring event, this is the end time of the first instance.对于重复事件,这是第一个实例的结束时间。

This means that you should modify这意味着你应该修改

            {
                DateTime = lastDayNextMonth,
                TimeZone = "Asia/Kolkata",
            }

to

            End = new EventDateTime()
            {
                DateTime = start + TimeSpan.FromMinutes(30),
                TimeZone = "Asia/Kolkata",
            }

Sample:样本:

            Start = new EventDateTime()
            {
                DateTime = "2021-11-01T09:00:00",
                TimeZone = "Asia/Kolkata",
            }
            End = new EventDateTime()
            {
                DateTime = "2021-11-01T09:30:00",
                TimeZone = "Asia/Kolkata",
            }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 c# 和 Google API 在 Google 日历中创建事件? - How to create an event in Google Calendar using c# and Google API? 如何使用C#和Google日历API创建Google日历活动? - How to create a Google calendar event with C# and Google calendar API? 使用C#在excel中查找每个月的最小值和最大值 - Find the min and max value in every month in excel using c# 如何使用 Google 日历 API 在 C# 中的 Google Meet 中创建带有视频会议的活动? - How to create event with videoconference in Google Meet in C# using Google Calendar API? 如何使用C#在Outlook 2007中召开会议(在日历中)? - How to make meeting (in calendar) in outlook 2007 using C#? C#无法使用API​​将事件插入Google日历 - C# Can't insert event to Google Calendar using API 如何使用 SSIS 组件 (C#) 和 Google.Apis.AnalyticsReporting.v4 ETL 谷歌分析数据 - How ETL the google analytics data by using SSIS component (C#) and Google.Apis.AnalyticsReporting.v4 防止 Google 日历 API V3 更改事件时间 C# - Preventing Google Calendar API V3 from changing event times C# 谷歌日历事件插入。NETC# - google calendar event insert .NET c# 用C#计算Google日历事件的持续时间 - Calculate Google Calendar event duration in C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM