当前位置:K88软件开发文章中心编程语言AspAsp01 → 文章内容

asp编程中常用的时间转数字,时间转字符串的方法

减小字体 增大字体 作者:佚名     来源:asp编程网  发布时间:2018-12-30 8:33:43

asp编程开发中经常遇到一些与时间有关的操作:如:将2011-8-10 16:16:15转换成20110810161615格式的方法,并不是2011810161615格式,因为要处理时间中数字小于10时,前面加个0。
<
%  str=now()  str=datetostr(str)  response.write str   '***************************************************  '函 数 名:datetostr  '作 用:根据给定的日期和时间型数据将其转换为yyyymmddhhiiss字符串格式  '参 数:d时间字符串  '返 回 值:转换后的字符串  '***************************************************  Function datetostr(d)  yyyy=Year(d)  mm=Month(d)  dd=Day(d)  hh=Hour(d)  ii=Minute(d)  ss=Second(d)  If Len(yyyy) =2 then  yyyy="20" &
yyyy  End If  If Len(mm)=1 then  mm="0" &
mm  End If  If Len(dd)=1 then  dd="0" &
dd  End If  If Len(hh)=1 then  hh="0" &
hh  End If  If Len(ii)=1 then  ii="0" &
ii  End If  If Len(ss)=1 then  ss="0" &
ss  End If  datetostr=yyyy &
mm &
dd &
hh &
ii &
ss  End Function%>
(鼠标移到代码上去,在代码的顶部会出现四个图标,第一个是查看源代码,第二个是复制代码,第三个是打印代码,第四个是帮助)


asp编程中常用的时间转数字,时间转字符串的方法