大众信息网

请问如何用VBS来定义时间格式

关注:66  答案:3  手机版
解决时间 2021-02-08 14:09
我获取的时间默认是这样的 2009-1-20 1:2:9我想将其转化为这样 2009-01-20 01:02:09请问应该如何操作啊谢谢
最佳答案
VBS里没有format()函数,简单的给你封个函数将就用吧
function formatdatetimes(datetime)

yy = year(datetime)
mn = month(datetime)
dd = day(datetime)
hh = hour(datetime)
mm = minute(datetime)
ss = second(datetime)

if cint(mn) <10 then mn = "0"&mn
if cint(dd) <10 then dd = "0"&dd

if cint(hh) <10 then hh = "0"&hh
if cint(mm) <10 then mm = "0"&mm
if cint(ss) <10 then ss = "0"&ss

formatdatetimes = yy &"-"& mn &"-"& dd &" "& hh &":"& mm & ":" & ss
end function

response.Write formatdatetimes("2009-1-20 1:2:9")
response.Write "<br>"
response.Write formatdatetimes(now)
%>
全部回答
d=date() Format(d,"YYYY-MM-DD HH:MM:SS")
vbs里没有format()函数,简单的给你封个函数将就用吧 function formatdatetimes(datetime) yy = year(datetime) mn = month(datetime) dd = day(datetime) hh = hour(datetime) mm = minute(datetime) ss = second(datetime) if cint(mn) &lt;10 then mn = "0"&amp;mn if cint(dd) &lt;10 then dd = "0"&amp;dd if cint(hh) &lt;10 then hh = "0"&amp;hh if cint(mm) &lt;10 then mm = "0"&amp;mm if cint(ss) &lt;10 then ss = "0"&amp;ss formatdatetimes = yy &amp;"-"&amp; mn &amp;"-"&amp; dd &amp;" "&amp; hh &amp;":"&amp; mm &amp; ":" &amp; ss end function response.write formatdatetimes("2009-1-20 1:2:9") response.write "&lt;br&gt;" response.write formatdatetimes(now) %&gt;
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!