<h1 class="headtit">在VB.NET中如何确定两个日期之间的天数</h1><h3 class="headaur"><a href="http://www.builder.com.cn/" target="_blank">开发者在线 Builder.com.cn</a> 更新时间:<cite>2007-03-27</cite>作者:<span>builder.com.cn</span> 来源:</h3><h2 class="headkeyw">本文关键词: <a href="http://www.builder.com.cn/list-0-0-12222-1-1.htm" target="_blank">DOTNET</a>3 B6 b5 v! v- C, [
<a href="http://www.builder.com.cn/list-0-0-23276-1-1.htm" target="_blank">dotnet</a>% V& p! q9 ~4 e) D: w* a
<a href="http://www.builder.com.cn/list-0-0-49221-1-1.htm" target="_blank">dotnet</a>1 h4 t4 ^4 I( p2 T1 s/ L) m
<a href="http://www.builder.com.cn/list-0-0-26591-1-1.htm" target="_blank">VB.Net</a>' |; ?* [3 e: L1 \! S. b
<a href="http://www.builder.com.cn/list-0-0-36776-1-1.htm" target="_blank">vb.net</a>% b% o' R& e! B% ^
<a href="http://www.builder.com.cn/list-0-0-47694-1-1.htm" target="_blank">VB.NET</a>) P9 R+ ~4 a) a; A" M( e/ O
<a href="http://www.builder.com.cn/list-0-0-49219-1-1.htm" target="_blank">VB.NET</a>+ L' M, C( ~% h# o' z/ j% W9 \' n) l' w
<a href="http://www.builder.com.cn/list-0-0-22622-1-1.htm" target="_blank">VB.NET</a>6 Z: G4 V. Y' v4 N+ G
<a href="http://www.builder.com.cn/list-0-0-49225-1-1.htm" target="_blank">vb.net</a>$ c' L8 ], _& z0 H2 U' g
</h2><div class="artl_con"><p>在应用开发中,开发人员经常要进行各种各样的日期处理。如果你需要一种简单的方法来计算出给定两个日期间的天数,不妨考虑使用VB.NET中的TimeSpan对象。</p><p><a href="http://www.builder.com.cn/2007/0327/383537.shtml" target="_blank">列表A</a>向你演示了如何使用TimeSpan对象来获得两个日期间的时间值。今后,你可以使用Subtract方法来获得两个日期间的实际天数。</p><p>关于列表A的一些说明</p><p>首先,我们声明一个Date类型的变量dtStartDate,并赋初值为2007年一月一日。同时,还声明了其它一些将会用到的变量,包括:TimeSpan的一个实例tsTimeSpan,整型数iNumberOfDays,字符串型变量strMsgText。设定变量tsTimeSpan的值为当前日期/时间值与dtStartDate值得差。</p><p>为了计算出当前日期/时间(Now)与dtStartDate之间的天数,我们使用TimeSpan对象的Days属性,设定它的值为iNumberOfDays 。然后,创建一个text对象,其值是将必要文本和strMsgText变量的值连接在一起,该对象将显示在消息框中,最后一步是在消息框中显示字符串变量strMsgText的值。</p><p>责任编辑:德东</p></div> |