关于时间日期格式的问题::变态老板变态问题!!!!!!!!正则方面

lio_sy 2003-11-12 02:50:05
03-11-12 13:39
03-11-12 13:39
03-11-3 13:38
03-11-3 13:36
03-10-31 9:42
===================================================================
如何将11-3补0,成11-03,9:42补0,成09:42

时间日期是用NOW取得的

各位高手帮帮忙吧!!我要疯了!!!!!!!
...全文
33 27 打赏 收藏 转发到动态 举报
写回复
用AI写文章
27 条回复
切换为时间正序
请发表友善的回复…
发表回复
龙华 2003-11-13
  • 打赏
  • 举报
回复
真是个笨蛋。
lovehwq21 2003-11-12
  • 打赏
  • 举报
回复
哈哈,楼主,很简单的错误,改改就OK了
超级大笨狼 2003-11-12
  • 打赏
  • 举报
回复
我们不仅要编程而且要造型,不仅要画蛇添足,画猪而且还要戴朵花
超级大笨狼 2003-11-12
  • 打赏
  • 举报
回复
thinking in VBS
编程艺术化
工作兴趣化
工具玩具化
牛人菜人化
菜人牛人化
zjou2003 2003-11-12
  • 打赏
  • 举报
回复
<script language=vbs>
x="03-9-2 12:45"
msgbox split(split(x)(0),"-")(0)
msgbox split(split(x)(0),"-")(1)
msgbox split(split(x)(0),"-")(2)
msgbox split(split(x)(1),":")(0)
msgbox split(split(x)(1),":")(1)
</script >
lio_sy 2003-11-12
  • 打赏
  • 举报
回复
另外lovehwq21的函数本来很好,可惜,第二个,CHGTIMEFORMAT不能用,遗憾。

lio_sy 2003-11-12
  • 打赏
  • 举报
回复
问题解决了,再次谢谢各位大侠的帮助!下面给分!

其中狼,真水无香,小虎, lovehwq21,是最感谢的。
超级大笨狼 2003-11-12
  • 打赏
  • 举报
回复
VBS 短暂的美,两个函数,整齐的代码,简单的思路,拯救年轻的大兵
<script language=vbs>
dim x,a,b,c,d,e
x="03-9-2 12:45"
a=split(split(x)(0),"-")(0)
b=split(split(x)(0),"-")(1)
c=split(split(x)(0),"-")(2)
d=split(split(x)(1),":")(0)
e=split(split(x)(1),":")(1)
if len(a)=1 then a ="0" & a
if len(b)=1 then b ="0" & b
if len(c)=1 then c ="0" & c
if len(d)=1 then d ="0" & d
if len(e)=1 then e ="0" & e
x=a & "-" & b &"-"& c & " " & d & ":"& e
msgbox x
</script >
rexsp 2003-11-12
  • 打赏
  • 举报
回复
天,刚才忙,所以忘记贴
既然写了,就贴吧

<%
Dim DateStrTest
DateStrTest="2003-10-3 9:42"
response.write FormatDate(DateStrTest)

Function FormatDate(DateStr)
Dim YearStr
Dim MonthStr
Dim DayStr
Dim HourStr
Dim MinuteStr
DateStr=FormatDateTime(DateStr)
YearStr=Year(DateStr)
MonthStr=Month(DateStr)
DayStr=Day(DateStr)
HourStr=Hour(DateStr)
MinuteStr=Minute(DateStr)

If Len(MonthStr)=1 Then MonthStr="0"&MonthStr
If Len(DayStr)=1 Then DayStr="0"&DayStr
If Len(HourStr)=1 Then HourStr="0"&HourStr

FormatDate=YearStr&"-"&MonthStr&"-"&DayStr&" "&HourStr&":"&MinuteStr
End Function
%>
lio_sy 2003-11-12
  • 打赏
  • 举报
回复
多谢各位,我正在调试,这个帖子使我收益非浅啊,大家都有分,谢谢
超级大笨狼 2003-11-12
  • 打赏
  • 举报
回复
更正:
<script language=vbs>
x="03-9-2 12:45"
msgbox split(split(x)(0),"-")(0)
msgbox split(split(x)(0),"-")(1)
msgbox split(split(x)(0),"-")(2)
msgbox split(split(x)(1),":")(0)
msgbox split(split(x)(1),":")(1)
</script >
超级大笨狼 2003-11-12
  • 打赏
  • 举报
回复
你再实验
<script language=vbs>
x="03-9-2 12:45"
msgbox split(split(x)(0),"-")(0)
msgbox split(split(x)(0),"-")(1)
msgbox split(split(x)(0),"-")(2)
msgbox split(split(x)(1),":")(0)
msgbox split(split(x)(0),"1")(1)
</script >
tigerwen01 2003-11-12
  • 打赏
  • 举报
回复
下面这段代码是最好的:
<%
dim YTime,MTime,DTime,HTime,MiTime
YTime=year(now())
MTime=Month(now())
DTime=Day(now())
HTime=Hour(now())
MiTime=Minute(now())

if len(YTime)=1 then
Ytime="0"&YTime
end if
if len(MTime)=1 then
Mtime="0"&MTime
end if
if len(DTime)=1 then
Dtime="0"&DTime
end if
if len(HTime)=1 then
Htime="0"&HTime
end if
if len(MiTime)=1 then
Mitime="0"&MiTime
end if
Response.Write "格式化的日期时间: "&Ytime&"-"&Mtime&"-"&Dtime&"

"&Htime&":"&Mitime
%>
超级大笨狼 2003-11-12
  • 打赏
  • 举报
回复
推荐一个技巧
<script language=vbs>
x="03-9-2 12:45"
msgbox split(x)(0)
</script >
tigerwen01 2003-11-12
  • 打赏
  • 举报
回复
<%
dim YTime,MTime,DTime,HTime,MiTime
YTime=year(now())
MTime=Month(now())
DTime=Day(now())
HTime=Hour(now())
MiTime=Minute(now())

if len(YTime))=1 then
Ytime="0"&YTime
end if
if len(MTime))=1 then
Mtime="0"&MTime
end if
if len(DTime))=1 then
Dtime="0"&DTime
end if
if len(HTime))=1 then
Htime="0"&HTime
end if
if len(MiTime))=1 then
Mitime="0"&MiTime
end if
Respons.Write "格式化的日期时间: "&Ytime&"-"&Mtime&"-"&Dtime&" "&Htime&":"&Mitime
%>
超级大笨狼 2003-11-12
  • 打赏
  • 举报
回复
我现在很疲劳,不想帮你写了。我现在连工作都懒的做了,上面说的函数还不够,我给你一个最新的脚本帮助文件吧。
http://download.microsoft.com/download/winscript56/Install/5.6/W982KMe/CN/scd56chs.exe
vbs做这个是特长。
超级大笨狼 2003-11-12
  • 打赏
  • 举报
回复
时间和字符串的判断处理,无外乎用到了
instr()
mid()
replace()
left()
right()
split()
join()
month(now())
day(now())
hour(now())
minute(now())
你碰到的问题,我遇到过n次了,没把他当问题啊。
lio_sy 2003-11-12
  • 打赏
  • 举报
回复
03-9-2 12:45
=================================================================
谁能写一个,除了03不判断,其他的都自动补0的函数

chense 2003-11-12
  • 打赏
  • 举报
回复
如果你是windows系统的话,直接修改区域选项里的短日期格式为yyyy-MM-dd
chense 2003-11-12
  • 打赏
  • 举报
回复
写个函数,用len()对month(now()),day(now()),hour(now()), minute(now())的长度进行判断,为1则在前面加0。
加载更多回复(7)

28,407

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧