无论如何我都会得到异常Could not parse date
.
In any case I get exception Could not parse date
.
日期格式有统一的公司标准-'dd/MM/yyyy'
There is unified company standard of date format - 'dd/MM/yyyy'
有些计算机具有不同的系统区域设置.我正在为 datepicker
使用 jQueryUI(它是小部件的标准,并且已经确定了 css 样式以匹配应用程序主题).
There are computers with different system locales. I am using jQueryUI for datepicker
( it is standard for widgets and already settled css styles to match application theme).
一开始,我没有找到更好的解决方案,然后使用 SimpleDateFormat
对象手动将日期字符串转换为日期对象.现在我有了转换器类,但仍然需要配置每个具有 java.util.Date
属性的操作.
At the beginning, I didn't found better solution then manually convert date string to date object using SimpleDateFormat
object. Now I have converter class but still need to configure every Action that has java.util.Date
property.
我正在使用 XML 配置,我确实尝试添加到 struts.xml
:
I am using XML configuration and I did try to add into struts.xml
:
<constant name="struts.date.format" value="dd/MM/yyyy" />
没用.
有什么可以强制所有 web 应用程序使用单一日期格式而不使用语言环境,只是输出和输入日期的统一格式?
Is there anything that can force all web-application to use single date format without locales just a unified format for output and input date?
或者我如何提取 Struts 日期类型转换器期望的日期格式,以便在发送到服务器之前使用 JS 转换日期以匹配 Struts 期望?
Or the way how I can extract date format expected by Struts date type converter, so I can use JS to convert date before to be sent to server to match Struts expectations?
Struts2 被设计为根据客户端请求的区域设置不同的行为.
Struts2 is designed to behave differently according to a locale requested by the client.
i18n
拦截器默认拦截器堆栈的成员.因此,它负责将请求的语言环境设置为操作上下文,覆盖默认设置.如果请求参数未请求区域设置,它还将该区域设置存储到会话以进一步检索它.
i18n
interceptor is a member of the default interceptor stack. So, it is responsible for setting requested locale to the action context, overriding the default settings. It also stores that locale to the session for further retrieving it if the locale is not requested by the request parameter.
动作上下文的语言环境由默认类型转换器使用,因此为动作上下文设置语言环境可能会覆盖可以通过 struts.locale
和 i18n 配置的默认语言环境设置
拦截器不会改变这一点.
The action context's locale is used by the default type converter, so setting a locale to the action context should probably override the default locale setting which could be configured via struts.locale
and i18n
interceptor doesn't change this.
如果是这样,则无需其他操作,只需根据该区域设置将您的日期格式设置为全局资源属性.您还可以使用可与 i18n
请求的语言环境一起使用的操作属性,该语言环境由于 处理本地化资源的顺序.
If so, no other actions required, just put your date format to the global resource properties according to that locale. You can also use action properties that could be used with i18n
requested locale that has different format due to the order of processing localization resources.
如果您不需要用户切换语言环境的可能性,您应该从堆栈中删除 i18n
拦截器.
If you don't need that possibility of switching a locale by the user you should remove i18n
interceptor from the stack.
如何使用操作上下文的语言环境格式化日期和数字:格式化日期和数字.
How to format the dates and numbers using action context's locale: Formatting Dates and Numbers.
这篇关于是否可以为整个struts webapp配置统一的日期格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!