ASP中格式化时间短日期补0变两位长日期的方法
程序员文章站
2022-06-09 17:15:23
因为短日期不足2位,所以在网页排版的时候,影响美观,下面两个函数可以解决这个问题。2020-2-7短日期 变 2020-02-07长日期function fstime(times) dim year...
因为短日期不足2位,所以在网页排版的时候,影响美观,下面两个函数可以解决这个问题。
2020-2-7短日期 变 2020-02-07长日期
function fstime(times) dim years,months,days if len(times)=0 then exit function years=year(times) months=right("0"&month(times),2) days=right("0"&day(times),2) times=years&"-"&months&"-"&days fstime=times end function
2020-2-7 23:37:5短日期 变 2020-02-07 23:37:05长日期
function fltime(times) dim years,months,days,hours,minutes,seconds if len(times)=0 then exit function years=year(times):months=right("0"&month(times),2) days=right("0"&day(times),2):hours=right("0"&hour(times),2) minutes=right("0"&minute(times),2):seconds=right("0"&second(times),2) fltime=years&"-"&months&"-"&days&" "&hours&":"&minutes&":"&seconds end function
pw_sys 日期格式转换函数
<% rem pw_sys 日期格式转换函数 function datetimeformat(datetime,format) select case format case "1" datetimeformat=""&year(datetime)&"年"&month(datetime)&"月"&right("0" & day(datetime),2)&"日" case "2" datetimeformat=""&month(datetime)&"月"&right("0" & day(datetime),2)&"日" case "3" datetimeformat=""&year(datetime)&"-"&month(datetime)&"-"&right("0" & day(datetime),2)&"" case "4" datetimeformat=""&year(datetime)&"/"&month(datetime)&"/"&right("0" & day(datetime),2)&"" case "5" datetimeformat=""&month(datetime)&"/"&right("0" & day(datetime),2)&"" case "6" datetimeformat=""&year(datetime)&"年"&month(datetime)&"月"&right("0" & day(datetime),2)&"日<font color=red> "&formatdatetime(datetime,4)&"</font>" case "7" temp="星期日,星期一,星期二,星期三,星期四,星期五,星期六" temp=split(temp,",") datetimeformat=temp(weekright("0" & day(datetime),2)-1) case "8" datetimeformat=""&month(datetime)&"-"&right("0" & day(datetime),2)&"" case "9" if len(hour(datetime)) = 1 then str="0"&hour(datetime) else str=hour(datetime) end if datetimeformat=datetimeformat(datetime,1)&" "&str&":"&minute(datetime) case "10" datetimeformat=""&year(datetime)&"年"&month(datetime)&"月" case else datetimeformat=datetime end select end function %>
程序代码(把yyyy-mm-dd格式的日期中的月份和日期转换成两位数字的方法)
dim today
today=date '避免重复调用date,所以赋值给一个变量
today=year(today) & "-" & right("0" & month(today),2) & "-" & right("0" & day(today),2)
asp中一段自动补位的函数
function formatsn(getnum,getbit) dim formatsnnum,formatsnpre,formatsnj formatsnnum = getbit – len(getnum) for formatsnj = 1 to formatsnnum formatsnpre = formatsnpre & "0" next formatsn = formatsnpre & getnum end function
使用方法
formatsn(getnum,getbit)
getnum 计数
getbit 共几位
以上就是asp中格式化时间短日期补0变两位长日期的方法的详细内容,更多关于asp短日期补0的资料请关注其它相关文章!
上一篇: JS 正则表达式从地址中提取省市县