您好我有以下代码:
Dim CurrentDate
CurrentDate = Date()
Dim intHour
Dim intMinute
Dim intSecond
intHour = 17
intMinute = 0
intSecond = 0
Dim NewDate
Dim NewDate1
Dim NewDate2
NewDate = DatePart("yyyy", CurrentDate)
NewDate1 = DatePart("m", CurrentDate)
NewDate2 = DatePart("d", CurrentDate)
Dim Dates
Dates = DateSerial(NewDate, NewDate1, NewDate2)
Dim Time
Time = TimeSerial(intHour, intMonth, intSecond)
我在VB中做了同样的事情:
Dim value As Date = Date.Now
Dim intHour As Integer
Dim intMinute As Integer
Dim intSecond As Integer
intHour = 17
intMinute = 0
intSecond = 0
Dim newdatetime As DateTime = New Date(value.Year, value.Month, value.Day, intHour, intMinute, intSecond)
在VB中我可以做到
Dim newdatetime As DateTime = New Date(value.Year, value.Month, value.Day, intHour, intMinute, intSecond).
在我的ASP代码中,我有Dates = DateSerial(NewDate, NewDate1, NewDate2)
和Time = TimeSerial(intHour, intMonth, intSecond)
。我怎样才能像在VB中一样将它们组合在一起?
答案 0 :(得分:4)
两种方式:
dim h,n,s
h = 17
n = 1
s = 2
dim t
t = timeserial(h,n,s)
dim d
d = date()
dim ts1
ts1 = dateadd("h",h, _
dateadd("n",n, _
dateadd("s",s, d )))
dim ts2
ts2 = d + T
两者都产生相同的输出。添加的一个有一些问题取决于你玩它的第0天。我认为第一种方式是“更健康”。据我所知,VBScript只是将日期部分存储在整数或浮点数中,时间部分存储在float的小数部分(作为24小时日的部分,因此12:00为0.5),因此您只需添加他们和+
一起