当前位置:asp编程网>技术教程>Asp教程>  正文

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

2011-11-22 13:45:13   来源:网络    作者:佚名   浏览量:3623   收藏
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
%>
(鼠标移到代码上去,在代码的顶部会出现四个图标,第一个是查看源代码,第二个是复制代码,第三个是打印代码,第四个是帮助)


关于我们-广告合作-联系我们-积分规则-网站地图

Copyright(C)2013-2017版权所属asp编程网