| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1983 人关注过本帖
标题:我这个split有错吗?为什么会有这样的结果?
只看楼主 加入收藏
hmhz
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:30
帖 子:1890
专家分:503
注 册:2006-12-17
收藏
得分:0 
再继续复杂完善一下
程序代码:

<%
function setdate(str1,str2)
    dim tem,tem1,tem2,tem3,tem4,tem5
    if instr(str1," ")<>0 then
        if str2=0 then
            tem=split(str1," ")   '把整个时间按空格分割,如:2008-9-4 , 8:3:2
            tem1=split(tem(0),"-")   '把日期分割,如:2008 , 9 , 4
            tem2=split(tem(1),":")   '把时间分割,如:8 , 3 , 2
            if len(tem1(1))=1 then   '当月长度等于1时
                   tem1(1)="0"&tem1(1)   '在前面加0
            end if
            if len(tem1(2))=1 then    '当日长度等于1时
                   tem1(2)="0"&tem1(2)    '在前面加0
            end if
            if len(tem2(0))=1 then    '当时长度等于1时
                   tem2(0)="0"&tem2(0)    '在前面加0
            end if
            if len(tem2(1))=1 then    '当分长度等于1时
                   tem2(1)="0"&tem2(1)    '在前面加0
            end if
            if len(tem2(2))=1 then    '当秒长度等于1时
                   tem2(2)="0"&tem2(2)    '在前面加0
            end if
            tem3=tem1(0)&"-"&tem1(1)&"-"&tem1(2)&" "&tem2(0)&":"&tem2(1)&":"&tem2(2)
            elseif str2=1 then
                str1=split(str1," ")(0)
                if instr(str1,"-")=0 then  '判断 "-" 不存在
                    tem4="格式不对"
                else
                    tem1=split(str1,"-")   '把日期分割,如:2008 , 9 , 4
                    if len(tem1(1))=1 then   '当月长度等于1时
                           tem1(1)="0"&tem1(1)   '在前面加0
                    end if
                    if len(tem1(2))=1 then    '当日长度等于1时
                           tem1(2)="0"&tem1(2)    '在前面加0
                    end if
                    tem4=tem1(0)&"-"&tem1(1)&"-"&tem1(2)
                end if
            elseif str2=2 then
                str1=split(str1," ")(1)
                if instr(str1,":")=0 then  '判断 ":" 不存在
                    tem5="格式不对"
                else
                    tem2=split(str1,":")   '把时间分割,如:8 , 3 , 2
                        if len(tem2(0))=1 then    '当时长度等于1时
                           tem2(0)="0"&tem2(0)    '在前面加0
                    end if
                    if len(tem2(1))=1 then    '当分长度等于1时
                           tem2(1)="0"&tem2(1)    '在前面加0
                    end if
                    if len(tem2(2))=1 then    '当秒长度等于1时
                           tem2(2)="0"&tem2(2)    '在前面加0
                    end if
                    tem5=tem2(0)&":"&tem2(1)&":"&tem2(2)
                end if
            end if
    elseif str2=0 then
            tem3="格式不对"
        elseif str2=1 then
                if instr(str1,"-")=0 then  '判断 "-" 不存在
                    tem4="格式不对"
                else
                    tem1=split(str1,"-")   '把日期分割,如:2008 , 9 , 4
                    if len(tem1(1))=1 then   '当月长度等于1时
                           tem1(1)="0"&tem1(1)   '在前面加0
                    end if
                    if len(tem1(2))=1 then    '当日长度等于1时
                           tem1(2)="0"&tem1(2)    '在前面加0
                    end if
                    tem4=tem1(0)&"-"&tem1(1)&"-"&tem1(2)
                end if
            elseif str2=2 then
                if instr(str1,":")=0 then  '判断 ":" 不存在
                    tem5="格式不对"
                else
                    tem2=split(str1,":")   '把时间分割,如:8 , 3 , 2
                        if len(tem2(0))=1 then    '当时长度等于1时
                           tem2(0)="0"&tem2(0)    '在前面加0
                    end if
                    if len(tem2(1))=1 then    '当分长度等于1时
                           tem2(1)="0"&tem2(1)    '在前面加0
                    end if
                    if len(tem2(2))=1 then    '当秒长度等于1时
                           tem2(2)="0"&tem2(2)    '在前面加0
                    end if
                    tem5=tem2(0)&":"&tem2(1)&":"&tem2(2)
                end if
    end if
Select Case str2
Case 0 setdate=tem3
Case 1 setdate=tem4
Case 2 setdate=tem5
End Select
end function
%>
<%=setdate("2008-9-4 8:3:2",0)%>  后面的参数0为整个时间格式化<br/>
<%=setdate("2008-9-4 8:3:2",1)%>  后面的参数1为只格式化日期<br/>
<%=setdate("2008-9-4 8:3:2",2)%>  后面的参数2为只格式化时间<br/>
<%=setdate("2008-9-4",1)%>        后面的参数1为格式化日期<br/>
<%=setdate("8:3:2",2)%>           后面的参数2为格式化时间<br/>

[编程论坛] ASP超级群:49158383  敲门暗号:ASP编程
龍艺博客 http://www.
2008-10-26 21:59
nicechlk
Rank: 3Rank: 3
等 级:论坛游侠
威 望:4
帖 子:330
专家分:187
注 册:2008-9-6
收藏
得分:0 
皇马果然asp高人。。。。佩服中。。。

莫以善小而不为,莫以恶小而为之!
2013-07-03 16:03
快速回复:我这个split有错吗?为什么会有这样的结果?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018101 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved