从时间跨度获取天数作为整数? [英] Get days as an int from a timespan?
本文介绍了从时间跨度获取天数作为整数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当前我有这个:
var x = Convert.ToString(dateTimePicker2.Value.Subtract(dateTimePicker1.Value));
int xDays = Convert.ToInt32(x.Substring(0,1));
但这很丑陋,让我内心不满(也无法在2位数的工作日内使用,例如15)。有更好的方法吗?
But it's ugly and makes me unhappy on the inside (Also doesn't work for 2 digit day spans, e.g. 15). Is there a better way to do this?
推荐答案
TimeSpan.Days 返回一个整数值,表示该时间跨度值的天分量。
TimeSpan.Days returns an integer value representing the days component of the timespan value.
var span = someDate.Subtract(anotherDate);
int days = span.Days;
这篇关于从时间跨度获取天数作为整数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文