Coldfusion日期转换:“2013-11-15T06:11:57.87是无效的日期或时间字符串” [英] Coldfusion date conversion: "2013-11-15T06:11:57.87 is an invalid date or time string"
问题描述
我尝试将日期从UTC转换为本地,并得到以下错误:
2013-11-15T06:11:57.87是无效的日期或时间字符串
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"
这里是部分代码:
#DateFormat(DateConvert("utc2Local", apiResult.Created), 'm/d/yy')#
正如你猜到的apiResult.Created是2013 -11-15T06:11:57.87
As you have guessed apiResult.Created is 2013-11-15T06:11:57.87
有什么想法吗?
谢谢
Any ideas? Thank you
推荐答案
您的问题似乎是字符串 2013-11-15T06 :11:57.87
不是可识别的日期字符串格式。你可能需要自己解析它。我发现这个例子为twitter日期,你可以修改为你的需要:
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>
更多信息: http://www.petefreitag.com/item/569.cfm
SimpleDateFormat的Java文档: http://docs.oracle.com/javase/7/docs /api/java/text/SimpleDateFormat.html
Java Documentation for SimpleDateFormat: http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html
根据Java文档,我认为您需要格式字符串:yyyy -MM-dd'T'HH:mm:ss.SS
Based on the Java documentation I think you need the format string: "yyyy-MM-dd'T'HH:mm:ss.SS"
注意,我读过一个注释,说明SimpleDateFormat类将时间到当地时间,你可能想检查这个。
Note that I did read a comment stating the SimpleDateFormat class converts the time to local time, you may want to check this.
这篇关于Coldfusion日期转换:“2013-11-15T06:11:57.87是无效的日期或时间字符串”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!