如何用正则表达式将形如2004-2-2或2004/2/2的日期格式化为2004-02-02的日期格式
如何用正则表达式将形如2004-2-2或2004/2/2的日期格式化为2004-02-02的日期格式 问题点数:20、回复次数:4Top
1 楼zltostem(五湖沸人)回复于 2004-09-03 10:24:04 得分 0
<%
Dim a,b,c,d
Dim i
a="2004-2-2"
if isdate(a) then
a=cdate(a)
d=cstr(year(a))
if month(a) < 10 then
b="0" & cstr(month(a))
else
b=cstr(month(a))
end if
if day(a) < 10 then
c="0" & cstr(day(a))
else
c=cstr(day(a))
end if
response.write d & "-" & b & "-" & c
end if
%>Top
2 楼wsb1979(春天的虫子)回复于 2004-09-03 10:46:05 得分 0
times=date()
date1=day(times)
if (date1<=9) then
date1="0"&date1
end if
month1=month(times)
if (month1<=9) then
month1="0"&month1
end if
year1=year(times)
timelast=year1&"-"&month1&"-"&date1Top
3 楼yaayaa2008()回复于 2004-09-03 11:49:14 得分 0
我的意思是我已经判断出是日期格式了,但想格式化成我需要的格式!Top
4 楼fason(咖啡人生)回复于 2004-09-03 13:01:07 得分 20
<script>
var re = /(\/|-)(\d)\b/g;
alert("2004-2-2".replace(re,"-0$2"));
alert("2004/2/2".replace(re,"-0$2"));
</script>Top




