新客网WWW.XKER.COM:致力做中国最专业的网络学院!
学院: 操作系统 - 网络应用 - 服务器 - 网络安全 - 工具软件 - 办公软件 - Web开发 - 数据库 - 网页设计 - 图形图像 - 媒体动画 - 硬件学堂 - 存储频道 - QQ专区
您的位置:首页 > 软件开发 > Web开发 > Asp教程 > 正文:一个处理各种日期格式的函数

一个处理各种日期格式的函数

新客网 XKER.COM 2003-07-11 来源: 收藏本文
<%
'----日期转化函数-----   
function wf_DateToChar(datetime,l)
    '---------说明------------
    'datetime是你要转化的日期值
    'l是你要转化到的层次,可设为"d"、"n"和"s"
    '"d"是指转化为yyyy-mm-dd形式
    '"n"是指转化为yyyy-mm-dd hh:mm形式
    '"s"是指转化为yyyy-mm-dd hh:mm:ss形式
    '"long"是指转化为yyyy年mm月dd日的形式
    '"no"是指转化为yyyymmdd的形式
    '"short"是指转化为yymmdd的形式
    '"t"是指转化为yymmdd hh:mm的形式
    '-------------------------
    dim ls_date,ls_getstr
    if isnull(l) or trim(l)="" then l="s"
    if isdate(datetime) then  
        ls_date=cstr(datetime)   
        'writeln  ls_date
        ls_getstr=DatePart("yyyy",cdate(ls_date))
        ls_getstr=ls_getstr & "-" & wf_ctonstr(DatePart("m",cdate(ls_date)),2)
        ls_getstr=ls_getstr & "-" & wf_ctonstr(DatePart("d",cdate(ls_date)),2)
        if l="d" then wf_DateToChar=ls_getstr
        ls_getstr=ls_getstr & " " & wf_ctonstr(DatePart("h",cdate(ls_date)),2)
        ls_getstr=ls_getstr & ":" & wf_ctonstr(DatePart("n",cdate(ls_date)),2)
        if l="n" then wf_DateToChar=ls_getstr
        ls_getstr=ls_getstr & ":" & wf_ctonstr(DatePart("s",cdate(ls_date)),2)
        if l="s" then wf_DateToChar=ls_getstr
        if l="long" then wf_DateToChar=DatePart("yyyy",cdate(ls_date))&"年"&wf_ctonstr(DatePart("m",cdate(ls_date)),2)&"月"&wf_ctonstr(DatePart("d",cdate(ls_date)),2)&"日"
        if l="no"   then wf_DateToChar=DatePart("yyyy",cdate(ls_date))&wf_ctonstr(DatePart("m",cdate(ls_date)),2)&wf_ctonstr(DatePart("d",cdate(ls_date)),2)
        if l="short"   then wf_DateToChar=right(DatePart("yyyy",cdate(ls_date)),2)&wf_ctonstr(DatePart("m",cdate(ls_date)),2)&wf_ctonstr(DatePart("d",cdate(ls_date)),2)
        if l="t" then wf_DateToChar=wf_ctonstr(DatePart("m",cdate(ls_date)),2)&wf_ctonstr(DatePart("d",cdate(ls_date)),2)&" "& wf_ctonstr(DatePart("h",cdate(ls_date)),2)& ":" & wf_ctonstr(DatePart("n",cdate(ls_date)),2)
        
    else
        wf_DateToChar=Null
    end if
    
end function
'----把一位整数转化为两位整数----"1" to "01"
function wf_ctonstr(num,n)
if not IsNumeric(num) then
    wf_ctonstr=num
else
    if len(cstr(cint(num)))>=n then
        wf_ctonstr=cstr(cint(num))
    else
        wf_ctonstr="0"&cstr(cint(num))
        while len(wf_ctonstr)<n
            wf_ctonstr="0"&cstr(wf_ctonstr)
        wend
    end if
end if
end function
'-----------------------------------

%>
收藏】 【评论】 【推荐】 【投稿】 【打印】 【关闭
发表评论
要记得去论坛讨论,点击注册新会员匿名评论
评论内容:不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
阅读排行
随机推荐
实用信息推荐