如何在Google Calendar Integration中将时区设置为null? [英] How can I set the time zone as null in Google Calendar Integration?

查看:89
本文介绍了如何在Google Calendar Integration中将时区设置为null?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经用ASP.NET MVC编写了与Google日历API集成的代码,并将事件设置到用户的日历中.我的代码是:

I have written a code in ASP.NET MVC that integrates with google calendar API and sets an event into the user's calendar. My Code is :

 public static string CreateEvent(CalendarEventViewModel model)
        {
            string Id = "";
            // List events.
            Event newEvent = new Event()
            {
                Summary = model.Summary,
                Location = model.Location,
                Description = model.Description,
                Start = new EventDateTime()
                {
                    DateTime = DateTime.Parse(model.StartDateTime),
                    TimeZone = "America/Los_Angeles",
                },
                End = new EventDateTime()
                {
                    DateTime = DateTime.Parse(model.EndDateTime),
                    TimeZone = "America/Los_Angeles",
                },
                Recurrence = new String[] { "RRULE:FREQ=DAILY;COUNT=1" },
                Attendees = new EventAttendee[] 
                {
                     new EventAttendee() { Email = model.CompanyEmailAddress },
                },
                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";
            if (model.IsInsert)
            {
              Event createdEvent =   SharedService.service.Events.Insert(newEvent, calendarId).Execute();
              Id = createdEvent.Id;
            }
            else
            {
                SharedService.service.Events.Update(newEvent, calendarId, model.Id).Execute();
                Id = "";
            }
            return Id;
        }

它工作正常,但是在这里我需要删除时区或将其设置为空 TimeZone ="America/Los_Angeles",,因为管理员和用户的时区不同.例如:-如果管理员将事件设置为上午5:00,则由于当前时区不同,用户的Google日历中事件的时间也必须为5:00.我该怎么办?

It works perfectly but here I need to remove the timezone or set it to null TimeZone = "America/Los_Angeles", because the admin and user's time zone are different. For example:- If admins set the event for 5:00 am, then the time for events in the user's google calendar also must be 5:00 am due to the timezone currently there are different. How Can I do this?

我尝试从代码中删除时区部分,但是我收到一条错误消息,提示时区丢失.

I tried removing the timezone part from the code but I got an error saying the timezone was missing.

推荐答案

问题:

您需要在 start.dateTime start.timeZone 中指定一个timeZone.从 API文档:

Issue:

You need to specify a timeZone, either in start.dateTime or in start.timeZone. From the API docs:

start.dateTime :时间,以组合的日期时间值(根据RFC3339格式)设置.需要时区偏移,除非在timeZone中明确指定了时区.

start.dateTime: The time, as a combined date-time value (formatted according to RFC3339). A time zone offset is required unless a time zone is explicitly specified in timeZone.

说明:

需要时区以便为事件指定特定的dateTime.它指示dateTime所指的时区.例如,假设时间为 5:00 AM .5:00 AM在哪里?在洛杉矶?在尼泊尔?洛杉矶的5:00 AM与尼泊尔的5:00 AM不同.而特定事件只能在特定时间开始.如果开始于洛杉矶的5:00 AM,则开始于(我认为)加德满都的5:45 PM.您无法在洛杉矶和加德满都的凌晨5:00开始举办特定活动:那是两个不同的时间!

Explanation:

A timezone is needed in order to specify a specific dateTime for the event. It indicates which timezone the dateTime refers to. For example, let's say the time is 5:00 AM. 5:00 AM where? In LA? In Nepal? 5:00 AM in LA is not the same time as 5:00 AM in Nepal. And a specific event can only start at a specific time. If it starts at 5:00 AM in LA, it starts at (I think) 5:45 PM in Kathmandu. You cannot have a specific event starting both at 5:00 AM in LA and in Kathmandu: that's two different times!

因此,以下操作是不可能的.如果两个用户(及其日历)位于不同的时区,则特定事件将在不同的时间显示:

So, the following is not possible. If two users (and their Calendars) are in different timezones, a specific event will show in different times:

例如:-如果管理员将事件设置为上午5:00,则由于当前时区不同,用户的Google日历中事件的时间也必须为5:00.

For example:- If admins set the event for 5:00 am, then the time for events in the user's google calendar also must be 5:00 am due to the timezone currently there are different.

当然,您始终可以更改日历的时区(请参阅更改一个日历的时区

Of course, you can always change the time zone for your Calendar (see section Change the time zone of one calendar here), but this won't change the actual time an event starts; it will just show the start times in a different time zone. An event starting at 5:00 AM LA time will still start at 5:45 PM Nepal time.

如果您确实希望某个事件在洛杉矶和加德满都的凌晨5:00开始,则您将不得不创建两个不同的事件.

这篇关于如何在Google Calendar Integration中将时区设置为null?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆