将RSS日期/时间字符串解析为日期/时间对象
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了将RSS日期/时间字符串解析为日期/时间对象相关的知识,希望对你有一定的参考价值。
Parsing an RSS date/time value (as a string) into a date/time object in ColdFusion.And more additional text.
<cffunction access="public" name="ParseAtomDate" returntype="date" displayname="ParseAtomDate" description="Parses a date from an Atom feed"> <cfargument name="feeddate" type="string" required="yes" displayname="The date in string format as displayed in the feed"> <cfset LOCAL.year = Left( ARGUMENTS.feeddate, 4 )/> <cfset LOCAL.year = LSParseNumber( LOCAL.year )/> <cfset LOCAL.start = Find( "-", ARGUMENTS.feeddate ) + 1/> <cfset LOCAL.end = Find( "-", ARGUMENTS.feeddate, LOCAL.start )/> <cfset LOCAL.month = Mid( ARGUMENTS.feeddate, LOCAL.start, LOCAL.end - LOCAL.start )/> <cfset LOCAL.month = LSParseNumber( LOCAL.month )/> <cfset LOCAL.start = LOCAL.end + 1/> <cfset LOCAL.end = Find( "T", ARGUMENTS.feeddate, LOCAL.start )/> <cfset LOCAL.day = Mid( ARGUMENTS.feeddate, LOCAL.start, LOCAL.end - LOCAL.start )/> <cfset LOCAL.day = LSParseNumber( LOCAL.day )/> <cfset LOCAL.start = LOCAL.end + 1/> <cfset LOCAL.end = Find( ":", ARGUMENTS.feeddate, LOCAL.start )/> <cfset LOCAL.hour = Mid( ARGUMENTS.feeddate, LOCAL.start, LOCAL.end - LOCAL.start )/> <cfset LOCAL.hour = LSParseNumber( LOCAL.hour )/> <cfset LOCAL.start = LOCAL.end + 1/> <cfset LOCAL.end = Find( ":", ARGUMENTS.feeddate, LOCAL.start )/> <cfset LOCAL.minute = Mid( ARGUMENTS.feeddate, LOCAL.start, LOCAL.end - LOCAL.start )/> <cfset LOCAL.minute = LSParseNumber( LOCAL.minute )/> <cfset LOCAL.start = LOCAL.end + 1/> <cfset LOCAL.end = Find( "-", ARGUMENTS.feeddate, LOCAL.start )/> <cfset LOCAL.second = Mid( ARGUMENTS.feeddate, LOCAL.start, LOCAL.end - LOCAL.start )/> <cfset LOCAL.second = LSParseNumber( LOCAL.second )/> <cfreturn CreateDateTime( LOCAL.year, LOCAL.month, LOCAL.day, LOCAL.hour, LOCAL.minute, LOCAL.second )/> </cffunction>
以上是关于将RSS日期/时间字符串解析为日期/时间对象的主要内容,如果未能解决你的问题,请参考以下文章
Swift 2:将 RSS pubDate 解析为 NSDate 对象
C# SyndicationFeed - RSS 解析日期问题