我正在尝试从 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/