我有一个我在Coldfusion 10中创建的项目,它已经差不多完成了,但我只需要显示自XML Feed中的上次更新以来的时间。我知道这不应该太难,但我似乎无法弄明白。
项目是通过来自出版物的XML Feed以及Feed中的所有pubdate提供的,我需要找出哪个pubdate是最新的(它们可能不是按照订阅源的时间顺序)。我还需要将Feed中最新的pubdate与当前本地时间(PDT)和饲料中的pubdates列在GMT中进行比较。我已经解析了XML,并且在名为“rssDate”的变量中捕获了pubdates,并且pubdates的格式如下:{ts'2014-06-27 20:48:46'}。
以下是所需的元素
自上次更新以来的时间颜色编码输出基于时间范围
<cfif timeDifference LT 1>
<cfset meterColor = "4bbd07">
<cfset colorName = "Green">
<cfset messageText = "Updated less than one hour ago">
<cfelseif timeDifference GTE 1 AND timeDifference LT 1.3>
<cfset meterColor = "64ff06">
<cfset colorName = "Lime">
<cfset messageText = "Updated less than one and a half hours ago">
<cfelseif timeDifference GTE 1.3 AND timeDifference LT 2>
<cfset meterColor = "fffc06">
<cfset colorName = "Yellow">
<cfset messageText = "Updated more than two hours ago">
<cfelseif timeDifference GTE 2 AND timeDifference LT 2.3>
<cfset meterColor = "fdae15">
<cfset colorName = "Orange">
<cfset messageText = "Updated more than two hours ago">
<cfelseif timeDifference GTE 2.3 AND timeDifference LT 3>
<cfset meterColor = "ff00fc">
<cfset colorName = "Pink">
<cfset messageText = "Updated more than two and a half hours ago">
<cfelseif timeDifference GTE 3>
<cfset meterColor = "fe0000">
<cfset colorName = "Red">
<cfset messageText = "Updated more than three hours ago">
</cfif>
答案 0 :(得分:0)
有很多方法可以做到这一点。一个是因为PDT比GMT落后7个小时。在你的PDT时间增加7个小时将使它成为GMT然后你可以比较两者。 (你可以在一条线上完成所有这一切,只是为了更清晰地分解它)
<cfset myGMTTime=DateAdd("h",7,now())>
<cfset rssDat="2014-06-27 20:48:46"> <!---as you said you have this figured out--->
<cfset timeElapsed=DateDiff("n",myGMTTime,rssDate)><!---can use "h" for hours or "s" for seconds. It is "n" for minutes. "m" is used for months--->