ASP读取日期单日期自动补零函数

发布时间:2015年4月29日 作者:未知 查看次数:1458

ASP读取日期单日期自动补零函数


自:http://www.jb51.net/article/25902.htm

fillzero 函数:月和日这两个日期如果是单数的话前面补0。如2011年3月3日一般格式是2011-3-3通过函数转化成2011-03-03这样的格式。
 
代码:
public function fillzero(l1)
if len(l1)=1 then
fillzero="0"&l1
else
fillzero=l1
end if
end function
 
用法示例:

response year(now)&month(now)&day(now) 结果:201116
response year(now)&fillzero(month(now))&fillzero(day(now)) 显示结果:20110106
 
如何控制长日期格式和短日期格式的显示:

Short Date:FORMATDATETIME(DATE,vbShortDate)
Long Date:FORMATDATETIME(DATE,vbLongDate)

当根据英国(美国)区域设置显示日期时,日期显示为如下的格式:

Short Date:7/9/97
Long Date:Wednesday,July 09,1997

注意:短日期格式的显示与不做任何格式化时完全相同。在缺省情况下,日期以短日期格式显示。

如何用FORMATDATETIME()函数操作时间:

Short Time:FORMATDATETIME(TIME,vbShortTime)
Long Time:FORMATDATETIME(TIME,vbLongTime)

当以英国(美国)区域设置显示时间时,时间的格式如下:

Short Time:03:20
Long Time:3:20:08 AM
代码如下:

<%
function FillZero(str)
ttt=str
if len(str)=1 then
ttt="0" & str
end if
FillZero=ttt
end function
'转化日期,将 一位补上零 2003-1-2 --> 2003-01-02
function ConvertDate(tDate)
ttt=tDate
if isdate(tDate) then
ttt=year(tDate) & "-" & FillZero(month(tDate)) & "-" & FillZero(day(tDate))
end if
ConvertDate=ttt
end function
'输入一个日期时间串,转换成年四位,其他两位的新的日期时间串
function ConvertDateTime(tDateTime)
ttt=tDateTime
if isdate(tDateTime) then
ttt=year(tDateTime) & "-" & FillZero(month(tDateTime)) & "-" & FillZero(day(tDateTime)) & " " & FillZero(cstr(hour(tDateTime))) & ":" & FillZero(cstr(minute(tDateTime))) & ":" & FillZero(cstr(second(tDateTime)))
end if
ConvertDateTime=ttt
end function
%>
 


版权所有!www.sieye.cn
E.Mail:sieye@sohu.com QQ:66697110