【发布时间】:2019-11-19 23:03:30
【问题描述】:
我试图获取两个日期之间的数字:
DateTime base;
....
base = DateTime.ParseExact(pos[13], "dd/MM/yyyy HH:mm:ss", CultureInfo.InvariantCulture);
//example base = 2014-06-21 17:00:00
DateTime col_N;
//then some for loop
col_N = DateTime.ParseExact(pos[k], "dd/MM/yyyy HH:mm:ss", CultureInfo.InvariantCulture);
//example col_N = 2014-06-22 00:00:00
为了得到我正在做的天数,如下所示:
int date_diff = (col_N - base).Days;
但它返回我 0。
另外,当我检查时:
string diff_dat2 = (col_N - base).TotalDays.ToString();
我得到了 0,291666666666667。
如何纠正它以获得 1 天?
【问题讨论】:
-
不清楚你在问什么。您只想将数字四舍五入到 1 吗?在本例中,一天 7/24 是正确答案,那么您要更正什么?
-
如果日期之间的差异只有 1 秒会发生什么?它还应该在 1 天后回来吗?还是您只是想要
datetime的date组件之间的区别?
标签: c# date datetime parsing datetime-parsing