这几天想做一个自动生成rss.xml的asp程序,主要是通过fso生成xml文件!程序简单,但是在做好之后发现pubdate标签里的时间无法显示,最后发现时间格式不对!
获取的时间格式是:2008-9-10 2:30:20格式,这种格式不能显示在页面之中!而正确的格式应该是20080910023020,这样才能正确显示出来,需要一个时间转换函数才能解决!函数如下:
Function FillZero(str,sLen)
dim tStr,lStr,i,zNum
lStr = len(str)
if lStr<sLen then
for i = 0 to sLen - lStr -1
tStr = tStr & “0″
next
end if
tStr= tStr & str
FillZero=tStr
end function
Function ConvertDateTime(tDateTime,tType)
dim tTime
tTime=tDateTime
if isdate(tDateTime) then
Select Case tType
Case 1 ‘格式:20080526090800
tTime=year(tDateTime) & FillZero(month(tDateTime),2) & FillZero(day(tDateTime),2) & FillZero(cstr(hour(tDateTime)),2) & FillZero(cstr(minute(tDateTime)),2) & FillZero(cstr(second(tDateTime)),2)
Case 2 ‘格式:20080526
tTime=year(tDateTime) & FillZero(month(tDateTime),2) & FillZero(day(tDateTime),2)
End Select
end if
ConvertDateTime=tTime
end function
函数中提到了两种格式,用第一种即可!
但是还有问题,显示的时间而不是本地的时间而是国际标准时间,还需要把时区设置一下就可以解决!时区设置的方法是在时间后加上+0800即可!


看完了要说点啥么?