日期时间插件CRM 2011 [英] datetime plugin crm 2011
问题描述
最近,我试图让在发票实体throuhg插件的自定义字段datetime值,发现它在CRM的形式显示的日期之前返回了一天。对于incstance,我进入的2013年7月1日在我的C#以下code回报的2013年6月30日
Recently, I tried to get datetime value from custom field in Invoice entity throuhg plugin and found that it returns a day before the date displayed in CRM form. For incstance, I entered "7/1/2013" and in my C# the following code returns "6/30/2013":
EntityReference eRef = new EntityReference(localContext.PluginExecutionContext.PrimaryEntityName, localContext.PluginExecutionContext.PrimaryEntityId);
var invoice = localContext.OrganizationService.Retrieve(eRef.LogicalName, eRef.Id, new ColumnSet(true));
string start = ((DateTime)invoice["revg_startdate"]).ToString(); //here I get 6/30/2013
然后我查了一下相关MS SQL表中的实际日期时间,和之前保持整整一天,2013年6月30日
日期,时间和时区的服务器上,我的电脑和CRM绝对相同。
The date, time and timezones are absolutely identical on server, my PC and in CRM.
为什么CRM保持并显示不同的日期?
Why CRM keeps and displays different dates?
推荐答案
动态CRM在数据库中存储为UTC时间所有日期。用户界面转换这个时候基于来自usersettings用户的本地时区。
Dynamics CRM stores all dates in the database as UTC time. The user interface the converts this time based on the users local time zone from the usersettings.
这样做的原因是,你可以在不同的时区的用户在同一个CRM组织工作和CRM具有存储在一个共同的格式的日期,以能够显示正确的日期和时间,以所有用户。
The reason for this is that you could have users in different time zones working on the same CRM organization, and CRM have to store the dates in a common format to be able to show the correct date and time to all users .
如果你想在你可以使用插件的本地时间 .ToLocalTime()
If you want the local time in a plugin you could use .ToLocalTime()
string start = ((DateTime)invoice["revg_startdate"]).ToLocalTime().ToString();
这篇关于日期时间插件CRM 2011的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!