c# - 如何防止 DateTime 在带有区域性信息的 XML 中序列化?

标签 c# datetime dynamics-crm cultureinfo dynamics-crm-2015

我正在尝试从 CRM 检索我的数据。但在这样做的同时,看起来它正在将文化应用于日期时间字段。

我已将 CRM 中的日期时间保存为 - 01/08/2017 12:00 AM。

但是当我在 FetchXML 的帮助下检索此数据时,它给了我 31/07/2017 06:30 PM

我已在我的 global.asax 文件中将文化设置为 -

 protected void Application_BeginRequest()
 {
     CultureInfo info = new CultureInfo(System.Threading.Thread.CurrentThread.CurrentCulture.ToString());
     info.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy";
     System.Threading.Thread.CurrentThread.CurrentCulture = info;
 }

和 web.config 文件 -

 <globalization culture="en-GB" />

现在当我从 CRM 检索数据时 -

foreach (var item in result2.Entities)
{
    model.SightTestDate = Convert.ToDateTime(item["oph_claimreceiveddate"]);
}

它给我的这个日期是 - 31/07/2017 06:30 PM

我在这里错过了什么?

最佳答案

使用 IOrganizationService 接口(interface)查询的记录中的常见日期字段将作为 UTC DateTime 值返回。

您需要将这些值转换为正确的时区。

关于c# - 如何防止 DateTime 在带有区域性信息的 XML 中序列化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45732788/

相关文章:

r - 在 R 中向 POSIXct 对象添加时间

c# - Microsoft Dynamics 365 SDK 核心程序集 .NET Core 移植错误

c# - 分析用户资格数据的最佳方式(C# 和 SQL 服务器)

c# - 将元素添加到 null(空)List<T> 属性

c# - 在 Linux 中运行用 Mono 编译的 C# 程序

c# - REngine' 不包含 'SetDllDirectory' 的定义,'RDotNet

datetime - 在 Coldfusion 中获取没有时间的日期的更短方法

python - 如何将 Pandas 数据框列从 np.datetime64 转换为日期时间?

c# - 动态 CRM SDK : Batch update specific fields in entity

dynamics-crm - 客户关系管理 2013 : Update a read-only field value using Business Rule