本文整理汇总了VB.NET中Microsoft.VisualBasic.DateAndTime.DateDiff方法的典型用法代码示例。如果您正苦于以下问题:VB.NET DateAndTime.DateDiff方法的具体用法?VB.NET DateAndTime.DateDiff怎么用?VB.NET DateAndTime.DateDiff使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。
在下文中一共展示了DateAndTime.DateDiff方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: InputBox
Dim date2Entered As String = InputBox("Enter a date")
Try
Dim date2 As Date = Date.Parse(date2Entered)
Dim date1 As Date = Now
' Determine the number of days between the two dates.
Dim days As Long = DateDiff(DateInterval.Day, date1, date2)
' This statement has a string interval argument, and
' is equivalent to the above statement.
'Dim days As Long = DateDiff("d", date1, date2)
MessageBox.Show("Days from today: " & days.ToString)
Catch ex As Exception
MessageBox.Show("Invalid Date: " & ex.Message)
End Try
示例2: DateDiff
' The following statements set datTim1 to a Thursday
' and datTim2 to the following Tuesday.
Dim datTim1 As Date = #1/4/2001#
Dim datTim2 As Date = #1/9/2001#
' Assume Sunday is specified as first day of the week.
Dim wD As Long = DateDiff(DateInterval.Weekday, datTim1, datTim2)
Dim wY As Long = DateDiff(DateInterval.WeekOfYear, datTim1, datTim2)
示例3:
Dim startTime As Date = Now
' Run the process that is to be timed.
Dim runLength As Global.System.TimeSpan = Now.Subtract(startTime)
Dim millisecs As Double = runLength.TotalMilliseconds