gpt4 book ai didi

java - dateTimeFormat 的有效掩码模式

转载 作者:搜寻专家 更新时间:2023-10-31 20:28:08 27 4
gpt4 key购买 nike

我得到了使用 dateTimeFormat 函数的代码。最初的开发者使用了“MM-HH-YY-dd-NN”的掩码。此代码可在他的机器上运行。它适用于我们的测试服务器。但它在我的本地机器上不起作用。我只有将掩码更改为“MM-HH-yy-dd-NN”才能使其工作;

注意这里的区别是大写的“YY”和小写的“yy”

https://wikidocs.adobe.com/wiki/display/coldfusionen/DateTimeFormat 查看文档看起来小写的 yy 是官方支持的做事方式。

有谁知道为什么 YY 在某些情况下会得到支持,而在其他情况下却不会?我怀疑它可能是某处的一些本地化代码,但我没有发现我的 CF 管理员和测试服务器上的管理员有任何区别。我可以在我的机器上做些什么来让 YY 工作吗?

我的机器是在 Mac 上运行的 Windows 7 虚拟机,而服务器是 Windows Server 2008。

我的 JVM 是 1.6.0_29 而服务器运行的是 1.7.0

这些差异是否足以解释问题?

下面是一些简单的测试代码:

<cfscript>
testTime=now();
lowermask= "MM-HH-yy-dd-NN";
uppermask= "MM-HH-YY-dd-NN";
result = {
lower=dateTimeFormat(testTime, lowermask)
,upper=dateTimeFormat(testTime, uppermask)
};
writedump(result);
</cfscript>

看起来问题出在底层 Java 版本中。我得到的错误是:

java.lang.IllegalArgumentException: Illegal pattern character 'Y'
at java.text.SimpleDateFormat.compile(SimpleDateFormat.java:768)
at java.text.SimpleDateFormat.initialize(SimpleDateFormat.java:575)
at java.text.SimpleDateFormat.<init>(SimpleDateFormat.java:500)
at coldfusion.util.DateUtils.getCFDateTimeFormat(DateUtils.java:673)
at coldfusion.util.DateUtils.formatDateTime(DateUtils.java:942)
at coldfusion.runtime.CFPage.LSDateTimeFormat(CFPage.java:1750)
at coldfusion.runtime.CFPage.LSDateTimeFormat(CFPage.java:1742)
at coldfusion.runtime.CFPage.DateTimeFormat(CFPage.java:1722)
at cftemp2ecfm333879290.runPage(C:\inetpub\wwwroot\temp.cfm:7)
at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:244)
at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:444)
at coldfusion.filter.CfincludeFilter.invoke(CfincludeFilter.java:65)
at coldfusion.filter.IpFilter.invoke(IpFilter.java:64)
at coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:449)
at coldfusion.filter.MonitoringFilter.invoke(MonitoringFilter.java:40)
at coldfusion.filter.PathFilter.invoke(PathFilter.java:112)
at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:94)
at coldfusion.filter.BrowserDebugFilter.invoke(BrowserDebugFilter.java:79)
at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28)
at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38)
at coldfusion.filter.NoCacheFilter.invoke(NoCacheFilter.java:58)
at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38)
at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22)
at coldfusion.filter.CachingFilter.invoke(CachingFilter.java:62)
at coldfusion.CfmServlet.service(CfmServlet.java:219)
at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:89)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at coldfusion.monitor.event.MonitoringServletFilter.doFilter(MonitoringServletFilter.java:42)
at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:46)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:928)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:414)
at org.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:204)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:539)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:298)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)

最佳答案

Java 已经改变了。 ColdFusion 不在乎。它直接传递掩码参数。

Java 7 文档中的一些亮点

Capital Y is a "week year"

A week year is in sync with a WEEK_OF_YEAR cycle. All weeks between the first and last weeks (inclusive) have the same week year value. Therefore, the first and last days of a week year may have different calendar year values.

If week year 'Y' is specified and the calendar doesn't support any week years, the calendar year ('y') is used instead.

关于java - dateTimeFormat 的有效掩码模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25547366/

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