使用 ASP Classic 将 RFC-32 日期格式转换为短日期 (MM/DD/YYYY)
我不是一个强大的 ASP Classic 开发人员,但我的任务是在工作中支持这个应用程序,我一直在尝试将 RSS 提要日期转换为短日期格式。 我似乎无法找到解决方案。
我有这种格式:
Wed, 10 Jun 2009 12:46:13 +0000
我需要将其转换为这种格式:
06/10/2009
到目前为止,我一直在修改 ASP 的 RSS 提要脚本:
<%
' change the RSSURL variable to the exact URL of the RSS Feed you want to pull
RSSURL = "{url to rss feed}"
Dim objHTTP ' this object is used to call the RSS Feed remotely
Dim RSSURL,RSSFeed ' these variables hold the URL and Content for the RSS Feed
Dim xmlRSSFeed ' this variable hold the XML data in a DOM Object
Dim objItems,objItem, objChild ' these variables are used to temporarily hold data from the various RSS Items
Dim title,description,link ' these are local variables that will hold the data to be displayed
Dim pubDate
Dim RSSOutput ' variable will hold the HTML that was converted from the RSS Feed
' this code requests the raw RSS/XML and saves the response as a string <RSSFeed>
Set objHTTP = Server.CreateObject("Msxml2.ServerXMLHTTP")
objHTTP.open "GET",RSSURL,false
objHTTP.send
RSSFeed = objHTTP.responseText
' this code takes the raw RSSFeed and loads it into an XML Object
Set xmlRSSFeed = Server.CreateObject("MSXML2.DomDocument.4.0")
xmlRSSFeed.async = false
xmlRSSFeed.LoadXml(RSSFeed)
' this code disposes of the object we called the feed with
Set objHTTP = Nothing
' this is where you determine how to display the content from the RSS Feed
' this code grabs all the "items" in the RSS Feed
Set objItems = xmlRSSFeed.getElementsByTagName("item")
' this code disposes of the XML object that contained the entire feed
Set xmlRSSFeed = Nothing
' loop over all the items in the RSS Feed
For x = 0 to 3
' this code places the content from the various RSS nodes into local variables
Set objItem = objItems.item(x)
For Each objChild in objItem.childNodes
Select Case LCase(objChild.nodeName)
Case "title"
title = objChild.text
Case "link"
link = objChild.text
Case "description"
description = objChild.text
Case "pubdate"
pubDate = objChild.text
End Select
Next
' Format display output
RSSOutput = RSSOutput & "<tr><td valign='top' style='width:75px; height: 34px;' class='addresstext2'><b>"& pubDate &"</b></td><td valign='top'><a class=ccc href=""" & link & """>" & title & "</a></td></tr>"
Next
%>
当我从 RSS 获取 pubDate 时,我相信它是一个字符串,当我尝试对其进行 CDate 时,我得到类型不匹配,我也尝试过 Format() 和相同的处理。 谁能建议一种方法将此日期格式化为我需要的格式?
谢谢!
I'm not a strong ASP Classic developer, but I am tasked with supporting this application at work, well I've been trying to convert an RSS feed date to a short date format. And I cannot seem to find a solution.
I have this format:
Wed, 10 Jun 2009 12:46:13 +0000
and I need to get it into this format:
06/10/2009
So far I have been tinkering with this RSS feed script for ASP:
<%
' change the RSSURL variable to the exact URL of the RSS Feed you want to pull
RSSURL = "{url to rss feed}"
Dim objHTTP ' this object is used to call the RSS Feed remotely
Dim RSSURL,RSSFeed ' these variables hold the URL and Content for the RSS Feed
Dim xmlRSSFeed ' this variable hold the XML data in a DOM Object
Dim objItems,objItem, objChild ' these variables are used to temporarily hold data from the various RSS Items
Dim title,description,link ' these are local variables that will hold the data to be displayed
Dim pubDate
Dim RSSOutput ' variable will hold the HTML that was converted from the RSS Feed
' this code requests the raw RSS/XML and saves the response as a string <RSSFeed>
Set objHTTP = Server.CreateObject("Msxml2.ServerXMLHTTP")
objHTTP.open "GET",RSSURL,false
objHTTP.send
RSSFeed = objHTTP.responseText
' this code takes the raw RSSFeed and loads it into an XML Object
Set xmlRSSFeed = Server.CreateObject("MSXML2.DomDocument.4.0")
xmlRSSFeed.async = false
xmlRSSFeed.LoadXml(RSSFeed)
' this code disposes of the object we called the feed with
Set objHTTP = Nothing
' this is where you determine how to display the content from the RSS Feed
' this code grabs all the "items" in the RSS Feed
Set objItems = xmlRSSFeed.getElementsByTagName("item")
' this code disposes of the XML object that contained the entire feed
Set xmlRSSFeed = Nothing
' loop over all the items in the RSS Feed
For x = 0 to 3
' this code places the content from the various RSS nodes into local variables
Set objItem = objItems.item(x)
For Each objChild in objItem.childNodes
Select Case LCase(objChild.nodeName)
Case "title"
title = objChild.text
Case "link"
link = objChild.text
Case "description"
description = objChild.text
Case "pubdate"
pubDate = objChild.text
End Select
Next
' Format display output
RSSOutput = RSSOutput & "<tr><td valign='top' style='width:75px; height: 34px;' class='addresstext2'><b>"& pubDate &"</b></td><td valign='top'><a class=ccc href=""" & link & """>" & title & "</a></td></tr>"
Next
%>
As I get pubDate from the RSS, I believe it is a string, and when I try to CDate it, I get a Type mismatch, I have also tried Format() and same deal. Can anyone suggest a method to format this date to what I need?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Rss 使用 RFC822 中指定的格式。
我在这个线程中找到了一个函数:
它还调用了一个名为monthVal的函数,该函数只是返回月份名称:
代码:
Rss uses the format specified in RFC822.
I found a function in this thread:
it also calls a function called monthVal, which just returns a number for a month name:
Code: