Coldfusion date conversion: “2013-11-15T06:11:57.87 is an invalid date or time string”

Deadly 提交于 2019-12-10 17:46:13

问题


I am trying to convert a date from UTC to local and I am getting the following error: "2013-11-15T06:11:57.87 is an invalid date or time string"

Here is the partial code:

#DateFormat(DateConvert("utc2Local", apiResult.Created), 'm/d/yy')#

As you have guessed apiResult.Created is 2013-11-15T06:11:57.87

Any ideas? Thank you


回答1:


Your problem seems to be that the string 2013-11-15T06:11:57.87 is not a recognised date string format. You're probably going to have to parse it yourself. I found this example for twitter dates which you could probably modify to your needs:

<cffunction name="parseTwitterDateFormat" output="false" returntype="String" hint="I return the date in a useable date format.">
  <cfargument name="twitterDate" required="true" type="string" hint="The Twitter date." />
  <cfset var formatter = CreateObject("java", "java.text.SimpleDateFormat").init("EEE MMM d kk:mm:ss Z yyyy") />
  <cfset formatter.setLenient(true) />
  <cfreturn formatter.parse(arguments.twitterDate) />
</cffunction>

More info: http://www.petefreitag.com/item/569.cfm

Java Documentation for SimpleDateFormat: http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html

Based on the Java documentation I think you need the format string: "yyyy-MM-dd'T'HH:mm:ss.SS"

Note that I did read a comment stating the SimpleDateFormat class converts the time to local time, you may want to check this.



来源:https://stackoverflow.com/questions/20088433/coldfusion-date-conversion-2013-11-15t061157-87-is-an-invalid-date-or-time-s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!