gpt4 book ai didi

Coldfusion 日期转换 : "2013-11-15T06:11:57.87 is an invalid date or time string"

转载 作者:行者123 更新时间:2023-12-02 00:03:11 26 4
gpt4 key购买 nike

我正在尝试将日期从 UTC 转换为本地日期,但出现以下错误:“2013-11-15T06:11:57.87 是无效的日期或时间字符串”

部分代码如下:

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

正如您猜到的 apiResult.Created 是 2013-11-15T06:11:57.87

有什么想法吗?谢谢

最佳答案

您的问题似乎是字符串 2013-11-15T06:11:57.87 不是可识别的日期字符串格式。您可能必须自己解析它。我找到了这个推特日期示例,您可以根据自己的需要进行修改:

<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 文档,我认为您需要格式字符串:"yyyy-MM-dd'T'HH:mm:ss.SS"

请注意,我确实阅读了一条评论,指出 SimpleDateFormat 类将时间转换为本地时间,您可能需要检查一下。

关于Coldfusion 日期转换 : "2013-11-15T06:11:57.87 is an invalid date or time string",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20088433/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com