public function fillzero(l1)
if len(l1)=1 then
fillzero="0"&l1
else
fillzero=l1
end if
end function [/code]
用法示例:- 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
- %>
复制代码
|