cloneDate复制一个Date对象。接收Date对象,输出该对象的复制。
Function cloneDate(myDate As Date)
cloneDate = DateAdd(DateInterval.Day, 0, myDate)
End Function
返回今天的15点整。
Function nowAtHour(myhour As Integer)
Dim mynow As Date
mynow = Now()
Dim myyear As Integer
myyear = Year(mynow)
Dim mymonth As Integer
mymonth = Month(mynow)
Dim myday As Integer = Day(mynow)
nowAtHour = New Date(myyear, mymonth, myday, myhour, 0, 0)
End Function
Dim myDate As Integer=nowAtHour(15)
因为Date对象的Second属性是只读的,不可以修改。所以写了设置秒数的方法。
Function setSecond(mysecond As Integer, mydate As Date)
Dim myyear As Integer = Year(mydate)
Dim mymonth As Integer = Month(mydate)
Dim myday As Integer = Day(mydate)
Dim myhour As Integer = Hour(mydate)
Dim myminute As Integer = Minute(mydate)
setSecond = New Date(myyear, mymonth, myday, myhour, myminute, mysecond)
End Function
设置分钟数
Function setMinute(myminute As Integer, mydate As Date)
Dim myyear As Integer = Year(mydate)
Dim mymonth As Integer = Month(mydate)
Dim myday As Integer = Day(mydate)
Dim myhour As Integer = Hour(mydate)
Dim mysecond As Integer = Second(mydate)
setMinute = New Date(myyear, mymonth, myday, myhour, myminute, mysecond)
End Function
设置小时数
Function setHour(myhour As Integer, mydate As Date)
Dim myyear As Integer = Year(mydate)
Dim mymonth As Integer = Month(mydate)
Dim myday As Integer = Day(mydate)
Dim myminute As Integer = Minute(mydate)
Dim mysecond As Integer = Second(mydate)
setHour = New Date(myyear, mymonth, myday, myhour, myminute, mysecond)
End Function
设置天数
Function setDay(myday As Integer, mydate As Date)
Dim myyear As Integer = Year(mydate)
Dim mymonth As Integer = Month(mydate)
Dim myhour As Integer = Hour(mydate)
Dim myminute As Integer = Minute(mydate)
Dim mysecond As Integer = Second(mydate)
setDay = New Date(myyear, mymonth, myday, myhour, myminute, mysecond)
End Function
设置月份
Function setMonth(mymonth As Integer, mydate As Date)
Dim myyear As Integer = Year(mydate)
Dim myday As Integer = Day(mydate)
Dim myhour As Integer = Hour(mydate)
Dim myminute As Integer = Minute(mydate)
Dim mysecond As Integer = Second(mydate)
setMonth = New Date(myyear, mymonth, myday, myhour, myminute, mysecond)
End Function
设置年份
Function setYear(myyear As Integer, mydate As Date)
Dim mymonth As Integer = Month(mydate)
Dim myday As Integer = Day(mydate)
Dim myhour As Integer = Hour(mydate)
Dim myminute As Integer = Minute(mydate)
Dim mysecond As Integer = Second(mydate)
setYear = New Date(myyear, mymonth, myday, myhour, myminute, mysecond)
End Function