SharePoint All Day Event gives obscure result

2019-07-13 07:45发布

问题:

I'm using the following code to create an All Day Event in a SharePoint calendar:

newitem = listobject.Items.Add()
guid = System.Guid.NewGuid()
            newitem["Name"] = "All Day Event " + guid.ToString()
            newitem["Title"] = "All Day Event " + guid.ToString()
            newitem["Start Time"] = System.DateTime.Now.Date
            newitem["End Time"] = System.DateTime.Now.Date
            newitem["Description"] = "Created by Automation Script"
            newitem["Location"] = "Location " + guid.ToString()
            newitem["UID"] = guid
            newitem["All Day Event"] = 1
            newitem.Update()
            print newitem["Created"]

However, when I query for the Created date of the created item (as in the last line ), it gives me the time in UTC. But in case of a Normal event or a recurrent event it gives me the local time. I tried to find the Kind property of the DateTime object, but it is set to Unspecified. The same problem occurs even if an All Day Event is created through the SharePoint site (manually). So I came to a conclusion that there is nothing wrong in the code. Please help me.

回答1:

See

SO SharePoint - all day events behave differently in CAML query