VB.Net 2005中,如何从(当前日期减去7天)基础上再减去若干天日期?
- 内容介绍
- 文章标签
- 相关推荐
本文共计243个文字,预计阅读时间需要1分钟。
我将提供一个日期,例如13/10/2008,需要减去当前日期(今天是28/09/2010)的7天,结果为21/09/2010。这样,减去13/10/2008,等价于erm,720。但显然,当前日期并不总是28/09/2010。我需要这个代码。编辑:
但显然,目前的日期并不总是28/09/2010.
我需要这个代码.
编辑:当我说未来我的意思是过去:)
Sub Main() Dim dt As DateTime = New DateTime(2008, 10, 13) ' be careful what you are subtracting from what ' the date you have is not in the future (year 2008) ' if the date is in the future: (dt.Subtract(DateTime.Now.AddDays(-7))).TotalDays ' or simply take the absolute value Dim days As Double = (DateTime.Now.AddDays(-7).Subtract(dt)).TotalDays Console.WriteLine(days) End Sub
您还会注意到TotalDays属性的类型为Double.
本文共计243个文字,预计阅读时间需要1分钟。
我将提供一个日期,例如13/10/2008,需要减去当前日期(今天是28/09/2010)的7天,结果为21/09/2010。这样,减去13/10/2008,等价于erm,720。但显然,当前日期并不总是28/09/2010。我需要这个代码。编辑:
但显然,目前的日期并不总是28/09/2010.
我需要这个代码.
编辑:当我说未来我的意思是过去:)
Sub Main() Dim dt As DateTime = New DateTime(2008, 10, 13) ' be careful what you are subtracting from what ' the date you have is not in the future (year 2008) ' if the date is in the future: (dt.Subtract(DateTime.Now.AddDays(-7))).TotalDays ' or simply take the absolute value Dim days As Double = (DateTime.Now.AddDays(-7).Subtract(dt)).TotalDays Console.WriteLine(days) End Sub
您还会注意到TotalDays属性的类型为Double.

