欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-08-05 22:10:59
复制代码 代码如下: public function fillzero(l1) if len(l1)=1 then fillzero="0"&l1 else fillzer...
复制代码 代码如下:

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
%>