首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >插件中的Crm DateTime问题

插件中的Crm DateTime问题
EN

Stack Overflow用户
提问于 2012-06-27 02:33:56
回答 1查看 6.5K关注 0票数 1

我有一个关于客户关系管理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)

在我的节目里我该怎么做。请告诉我一些想法。这是我的插件代码

代码语言:javascript
复制
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
}

EN

回答 1

Stack Overflow用户

发布于 2012-06-27 05:39:14

我以前曾面对过这个问题,使我发疯,解决办法是把世界协调时的时间转换为当地时间。

代码语言:javascript
复制
DateTime tenderDate = ((DateTime)target["new_tender"]).ToLocal();
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11218620

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档