如何防止 DateTime 在 XML 中使用文化信息进行序列化?

How can I prevent a DateTime from getting serialized in XML with culture information?

我正在尝试从 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"]);
}

给我这个日期是 - 2017 年 7 月 31 日 06:30 下午

我错过了什么?

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

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