我有一个关于客户关系管理DateTime问题的问题。在机会表单中有自定义的DateTime字段(投标提交日期),它显示在表单'Date only‘格式上。以及当投标提交日期更改时修改日期的其他字符串字段(投标日期)。让我们说..。投标日期为29/06/2011 12:00:00投标日期应为2012年6月29日
我创建插件,用于创建后操作和更新预操作。我检索TenderSubDate.Day,月份和年份。
客户关系管理时区是(GMT+08:00)吉隆坡,新加坡然后想改变(格林尼治时间-06:00)中央时间(美国和加拿大)。
问题是,当我根据投标提交日期更新投标日期时,该程序返回的日期比投标子日期少一天或少于一天。让我们说..。
First Secnario
投标日期为2012年6月29日12时:00
程序返回28/06/2012(it's错误,应该是29/06/2012)
第二塞纳里奥
投标日期为2012年08月1日12时:00
程序返回错误的32/07/2012(it's,应该是1/08/2012)
在我的节目里我该怎么做。请告诉我一些想法。这是我的插件代码
public class TenderSubDateChange : IPlugin
{
#region Class Level Variables
//IServiceProvider _serviceProvider;
//IOrganizationServiceFactory _serviceFactory = null;
//IOrganizationService _service = null;
//IPluginExecutionContext _context = null;
Entity _target = null;
Entity _preImage = null;
Entity _postImage = null;
Guid _currentUser;
#endregion
#region IPlugin Members
public void Execute(IServiceProvider serviceProvider)
{
try
{
string message = null;
IPluginExecutionContext _context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
#region Organization Services
// Obtain the organization service reference.
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(_context.UserId);
#endregion
var ServiceContext = new OrganizationServiceContext(service);
_currentUser = _context.UserId;
message = _context.MessageName.ToLower();
if (message == "create")//message == "create" ||
{
if (_context.InputParameters.Contains("Target") && _context.InputParameters["Target"] != null)
_target = (Entity)_context.InputParameters["Target"];
if (_context.PreEntityImages.Contains("PreImage") && _context.PreEntityImages["PreImage"] != null)
_preImage = (Entity)_context.PreEntityImages["PreImage"];
if (_context.PostEntityImages.Contains("PostImage") && _context.PostEntityImages["PostImage"] != null)
_postImage = (Entity)_context.PostEntityImages["PostImage"];
DateTime hm_tenderdate;
if (_target.Attributes.Contains("hm_tendersubmissiondate"))
{
hm_tenderdate = (DateTime)_target.Attributes["hm_tendersubmissiondate"];
_target.Attributes["hm_tendersubdate"] = (hm_tenderdate.Day) + "/" + hm_tenderdate.Month + "/" + hm_tenderdate.Year;
service.Update(_target);
}
}
if (message == "update")//message == "create" ||
{
if (_context.InputParameters.Contains("Target") && _context.InputParameters["Target"] != null)
_target = (Entity)_context.InputParameters["Target"];
if (_context.PreEntityImages.Contains("PreImage") && _context.PreEntityImages["PreImage"] != null)
_preImage = (Entity)_context.PreEntityImages["PreImage"];
if (_context.PostEntityImages.Contains("PostImage") && _context.PostEntityImages["PostImage"] != null)
_postImage = (Entity)_context.PostEntityImages["PostImage"];
DateTime hm_tenderdate;
if (_target.Attributes.Contains("hm_tendersubmissiondate"))
{
hm_tenderdate = (DateTime)_target.Attributes["hm_tendersubmissiondate"];
_target.Attributes["hm_tendersubdate"] = (hm_tenderdate.Day) + "/" + hm_tenderdate.Month + "/" + hm_tenderdate.Year;
}
}
}
catch (Exception ex)
{
throw new InvalidPluginExecutionException(ex.Message, ex);
}
}
#endregion
}

发布于 2012-06-27 05:39:14
我以前曾面对过这个问题,使我发疯,解决办法是把世界协调时的时间转换为当地时间。
DateTime tenderDate = ((DateTime)target["new_tender"]).ToLocal();https://stackoverflow.com/questions/11218620
复制相似问题