Max
Max

Reputation: 1309

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

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

Upvotes: 3

Views: 2155

Answers (1)

SpliFF
SpliFF

Reputation: 39014

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.

Upvotes: 3

Related Questions