gpt4 book ai didi

java - 根据语言环境确定日期时间模式

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

我有以下 JSF 代码来使用特定模式显示日期。

<f:convertDateTime pattern="E, d MMM, yyyy" timeZone="#{localeBean.timeZone}" />

我也想通过 localeBean 将模式传递给它。有什么办法可以根据语言环境确定具体的模式吗?

public LocaleBean() {
this.defaultTimeZone = TimeZone.getDefault();
this.strLocale = Locale.getDefault().toString();
this.timeZone = defaultTimeZone.getDisplayName();
}

最佳答案

f:convertDateTime为此提供了 typedateStyletimeStyle 属性,这取决于 viewroot 的语言环境。

假设 Facelets:

<!DOCTYPE html>
<html lang="#{localeBean.language}"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets">
<f:view locale="#{localeBean.locale}">
<h:head>
<title>SO question 4792373</title>
</h:head>
<h:body>
<h:outputText value="#{bean.date}">
<f:convertDateTime type="date" dateStyle="short" />
</h:outputText>
<br />
<h:outputText value="#{bean.date}">
<f:convertDateTime type="date" dateStyle="medium" />
</h:outputText>
<br />
<h:outputText value="#{bean.date}">
<f:convertDateTime type="date" dateStyle="long" />
</h:outputText>
<br />
<h:outputText value="#{bean.date}">
<f:convertDateTime type="date" dateStyle="full" />
</h:outputText>
</h:body>
</f:view>
</html>

这是它在英语语言环境中的呈现方式:

1/25/11Jan 25, 2011January 25, 2011Tuesday, January 25, 2011

德语:

25.01.1125.01.201125. Januar 2011Dienstag, 25. Januar 2011

荷兰语:

25-1-1125-jan-201125 januari 2011dinsdag 25 januari 2011

法语:

25/01/1125 janv. 201125 janvier 2011mardi 25 janvier 2011

等等

关于java - 根据语言环境确定日期时间模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4792373/

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