Souad
Souad

Reputation: 23

SetLocale with value "en_FR"

Hi I am new to JSP so sorry if my question is trivial. I tried to to research the answer with no luck.

Can anyone explain why the following wouldn't work

<fmt:setLocale value="en_FR" />  
<fmt:formatDate value="${dt}" type="both" var="now" />${now}

the current date/time will be shown in en_US locale.

Thanks

Upvotes: 2

Views: 6223

Answers (2)

Ashutosh Srivastav
Ashutosh Srivastav

Reputation: 669

If you want to compare Dates in France in US..I would do as below..

<jsp:useBean id="now" class="java.util.Date"  />

<fmt:setLocale value="fr_FR" scope="session"/>
Date in France:
<fmt:formatDate value="${now}" dateStyle="full"/> <br/>

<fmt:setLocale value="en_US" scope="session"/>
Date in US: 
<fmt:formatDate value="${now}" dateStyle="full" /> <br/>

The output is as..

Date in France: mercredi 14 janvier 2015  
Date in US: Wednesday, January 14, 2015 

Upvotes: 0

JB Nizet
JB Nizet

Reputation: 692043

en_FR means: in English, with the particularities of the English language from France. Since English isn't an official language in France, the JVM doesn't have any specific settings for the English locale in France, so it falls back to en: English.

And since there isn't anything different regarding dates between en and en_US, the format is the same.

Here's some test, and what it displays:

<fmt:setLocale value="en_FR" />
In English (FR): <fmt:formatDate value="${dt}" type="both" var="now" />${now}<br/>
<fmt:setLocale value="en_US" />
In English (US): <fmt:formatDate value="${dt}" type="both" var="now" />${now}<br/>
<fmt:setLocale value="en_UK" />
In English (UK): <fmt:formatDate value="${dt}" type="both" var="now" />${now}<br/>
<fmt:setLocale value="en" />
In English: <fmt:formatDate value="${dt}" type="both" var="now" />${now}<br/>
<fmt:setLocale value="fr" />
In French: <fmt:formatDate value="${dt}" type="both" var="now" />${now}<br/>

Display:

In English (FR): Jan 23, 2012 2:40:24 PM
In English (US): Jan 23, 2012 2:40:24 PM
In English (UK): Jan 23, 2012 2:40:24 PM
In English: Jan 23, 2012 2:40:24 PM
In French: 23 janv. 2012 14:40:24

Upvotes: 1

Related Questions