1.返回 “年-月-日”
s=split(date,"-")
s(1)=right("0" & s(1),2)
s(2)=right("0" & s(2),2)
sm=s(0)&"-"&s(1)&"-"&s(2)
msgbox sm
注意:其中date可以换成time、now等,我们也可以这样写:date的原本格式是:2008-11-6
t=now '同样now也可以换成time等
msgbox t
2.用格式函数 FormatDateTime()
Function GetCurrentDate
' FormatDateTime formats Date in long date.
GetCurrentDate = FormatDateTime(Date, 1)
End Function
msgbox GetCurrentDate
3.综合应用:VBScript生成唯一不重复的订单号
这块生成日期格式,如:20081106,主要是对日期格式进行了处理
y=split(date,"-") 'date 的格式是 2007-11-6
y(1)=right("0" & y(1),2)
y(2)=right("0" & y(2),2)
nian=y(0)&y(1)&y(2)
这块对时间格式进行了处理,将格式为:24:15:30处理成:241530
t=split(time,":")
shi=t(0)&t(1)&t(2)
这块生成随机数(0~9之间)
function rand(k,n)
Randomize
n=int((k-1)*rnd+1)
rand=n
end function
Dim n
n=rand(9,n)
OrderId=nian&shi&n ’组合 日期 时间 随机数 生成唯一的订单号 OrderId
msgbox OrderId