Datetime SharePoint Online在哪个时区保存日期时间日期

Datetime SharePoint Online在哪个时区保存日期时间日期,datetime,sharepoint-online,Datetime,Sharepoint Online,我在网上搜索过,但还没有找到SharePoint在数据库中保存DateTime对象的时区问题的答案。当用C#或PowerShell将日期返回给我时,它们总是休息一天。我的时区是W.欧洲标准时间。(瑞典斯德哥尔摩)如果我想与今天的日期进行比较,我应该如何转换返回的日期 更新 我根据您的示例构建了这段PowerShell代码。但是它找不到时区。我做错了什么 $strCurrentTimeZone=(获取WmiObject win32_时区)。标准名称 $TZ=[System.TimeZoneInfo

我在网上搜索过,但还没有找到SharePoint在数据库中保存DateTime对象的时区问题的答案。当用C#或PowerShell将日期返回给我时,它们总是休息一天。我的时区是
W.欧洲标准时间
。(瑞典斯德哥尔摩)如果我想与今天的日期进行比较,我应该如何转换返回的日期

更新

我根据您的示例构建了这段PowerShell代码。但是它找不到时区。我做错了什么

$strCurrentTimeZone=(获取WmiObject win32_时区)。标准名称

$TZ=[System.TimeZoneInfo]:findsystemtimezonebyd($strCurrentTimeZone)/我遇到了完全相同的问题

我用以下代码行在CSOM(C#)中修复了这个问题:

//Retrieve the date value from SP (1 day off in your case)
DateTime spDate = Convert.ToDateTime(spItem["DateField"]); 

//Retrieve the timezone from the SharePoint web
var spTimeZone = context.Web.RegionalSettings.TimeZone;
context.Load(spTimeZone);
context.ExecuteQuery();

//Get the System.TimeZoneInfo from Microsoft.SharePoint.Client.TimeZone
var fixedTimeZoneName = spTimeZone.Description.Replace("and", "&");
var timeZoneInfo = TimeZoneInfo.GetSystemTimeZones().Where(tz => tz.DisplayName == fixedTimeZoneName).FirstOrDefault();

//Setting the DateTimeKind to Unspecified (otherwise the last function could return an error)
spDate = DateTime.SpecifyKind(spDate, DateTimeKind.Unspecified);

//Getting destination timezone for the new Date
var europeanTimeZone = TimeZoneInfo.GetSystemTimeZones().Where(t => t.Id == "W. Europe Standard Time").FirstOrDefault();

//Converting the DateTime to your 'W.Europe Standard Time' timezone
DateTime correctDateTime = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(spDate, timeZoneInfo.Id, europeanTimeZone.Id); 

这将解决您的问题。

SharePoint以格式存储日期时间字段值,并在用户检索时将其转换为适当的时区。但是,在使用SharePoint API时,返回的日期为UTC格式,必须转换为本地时间

在C#/PowerShell中,日期时间可以通过以下方式转换为本地时间,例如:

 var list = ctx.Web.Lists.GetByTitle(listTitle);
 var item = list.GetItemById(itemId);
 ctx.Load(item);
 ctx.ExecuteQuery();

 var created = (DateTime)item["Created"];
 var createdLoc = System.TimeZone.CurrentTimeZone.ToLocalTime(created);

谢谢你的建议。我星期一第一件事就是试试看。整个周末都没有电脑。更新了我的question@Vladim最后,我将我的PowerShell重建为C#。你的建议在我的本地机器上很有效。但当我将C#代码放入Azure TimeTrigger函数时,它不会将SharePoint中的日期转换为正确的本地时间。你遇到这个问题了吗?谢谢你的建议。我星期一第一件事就是试试看。整个周末都没有电脑。