将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.
  1. <cffunction
  2. access="public"
  3. name="ParseAtomDate"
  4. returntype="date"
  5. displayname="ParseAtomDate"
  6. description="Parses a date from an Atom feed">
  7.  
  8. <cfargument
  9. name="feeddate"
  10. type="string"
  11. required="yes"
  12. displayname="The date in string format as displayed in the feed">
  13.  
  14. <cfset LOCAL.year = Left( ARGUMENTS.feeddate, 4 )/>
  15. <cfset LOCAL.year = LSParseNumber( LOCAL.year )/>
  16.  
  17. <cfset LOCAL.start = Find( "-", ARGUMENTS.feeddate ) + 1/>
  18. <cfset LOCAL.end = Find( "-", ARGUMENTS.feeddate, LOCAL.start )/>
  19. <cfset LOCAL.month = Mid( ARGUMENTS.feeddate, LOCAL.start, LOCAL.end - LOCAL.start )/>
  20. <cfset LOCAL.month = LSParseNumber( LOCAL.month )/>
  21.  
  22. <cfset LOCAL.start = LOCAL.end + 1/>
  23. <cfset LOCAL.end = Find( "T", ARGUMENTS.feeddate, LOCAL.start )/>
  24. <cfset LOCAL.day = Mid( ARGUMENTS.feeddate, LOCAL.start, LOCAL.end - LOCAL.start )/>
  25. <cfset LOCAL.day = LSParseNumber( LOCAL.day )/>
  26.  
  27. <cfset LOCAL.start = LOCAL.end + 1/>
  28. <cfset LOCAL.end = Find( ":", ARGUMENTS.feeddate, LOCAL.start )/>
  29. <cfset LOCAL.hour = Mid( ARGUMENTS.feeddate, LOCAL.start, LOCAL.end - LOCAL.start )/>
  30. <cfset LOCAL.hour = LSParseNumber( LOCAL.hour )/>
  31.  
  32. <cfset LOCAL.start = LOCAL.end + 1/>
  33. <cfset LOCAL.end = Find( ":", ARGUMENTS.feeddate, LOCAL.start )/>
  34. <cfset LOCAL.minute = Mid( ARGUMENTS.feeddate, LOCAL.start, LOCAL.end - LOCAL.start )/>
  35. <cfset LOCAL.minute = LSParseNumber( LOCAL.minute )/>
  36.  
  37. <cfset LOCAL.start = LOCAL.end + 1/>
  38. <cfset LOCAL.end = Find( "-", ARGUMENTS.feeddate, LOCAL.start )/>
  39. <cfset LOCAL.second = Mid( ARGUMENTS.feeddate, LOCAL.start, LOCAL.end - LOCAL.start )/>
  40. <cfset LOCAL.second = LSParseNumber( LOCAL.second )/>
  41.  
  42. <cfreturn CreateDateTime( LOCAL.year, LOCAL.month, LOCAL.day, LOCAL.hour, LOCAL.minute, LOCAL.second )/>
  43.  
  44. </cffunction>

以上是关于将RSS日期/时间字符串解析为日期/时间对象的主要内容,如果未能解决你的问题,请参考以下文章

Swift 2:将 RSS pubDate 解析为 NSDate 对象

将带有日期的字符串解析为日期时间对象[重复]

C# SyndicationFeed - RSS 解析日期问题

Java将字符串解析为日期返回不正确的日期

我可以禁用 openpyxl 自动将字符串解析为日期时间吗?

Java:解析日期字符串,时区缩写为Date对象