c# - 无法比较来自 CRM 和 Excel 的 2 个日期时间
问题描述
我在比较和的DateTime
值时遇到了问题。CRM
Excel
1. DateTime excelDT1 = Convert.ToDateTime(row[Excel.notificationdate].ToString().Trim(), System.Globalization.CultureInfo.GetCultureInfo("hi-IN").DateTimeFormat); ;
2. var excelDT2 = row[Excel.notificationdate].ToString().Trim();
3. var excelDT3 = row[Excel.notificationdate];
4. DateTime crmDT1 = Convert.ToDateTime(caseEntity.Attributes[Case.notificationdate].ToString().Trim(), System.Globalization.CultureInfo.GetCultureInfo("hi-IN").DateTimeFormat); ;
5. var crmDT2 = caseEntity.Attributes[Case.notificationdate].ToString().Trim();
6. var crmDT3 = caseEntity.Attributes[Case.notificationdate];
下面分别是输出:
- excelDT1:2020 年 1 月 13 日上午 12:00:00
- excelDT2:13/01/2020
excelDT3:13/01/2020
crmDT1:2020 年 12 月 1 日下午 4:00:00
- crmDT2:2020 年 1 月 12 日下午 4:00:00
- crmDT3:2020 年 1 月 12 日下午 4:00:00
我可以知道如何格式化上述内容,以便可以检查它们是否存在equal
?
谢谢你。
解决方案
您可以将 1st 和 4th 与public static bool Equals (DateTime t1, DateTime t2);
var result = DateTime.Equals(excelDT1, crmDT1);
推荐阅读
- android - Grafana iframe 如何
- c# - C# 遇到 UIAutomation 参考问题 - 未找到 get_BoundingRectangle() 方法
- java - IntelliJ + Maven Shade:发生 JNI 错误,请检查您的安装并重试
- bazel - 我可以依赖与模式匹配的所有 Bazel 目标,而不单独列出它们吗?
- sql - 平均时间戳数据在 postgres 中给出错误
- javascript - 在哪种情况下我们使用静态路由器或 BrowserRouter 或 HashRouter,为什么?
- mongodb - 每次执行查询时,聚合 $graphLookup 以不同的顺序检索结果?
- blogger - 可视化 Blogger 的数据
- openstack - Centos7.8安装openstack mitaka版本,控制节点安装镜像服务glance,镜像包含问题
- reactjs - React-connected-router 无法显示来自基本名称的图像