1

In my Postgresql database, I have a timestamp without time zone with this value : "2012-06-15 17:49:46.423" (default datatype used by Hibernate).

If I format with SimpleDateFormat and this pattern "EEEE dd MMMM yyyy", SimpleDateFormat#format returns "jeudi 14 juin 2012".

Why the result is not "vendredi 15 juin 2012" ?

French to English translation for non-french spoken :

"jeudi 14 juin 2012"    => "Thursday 14th of June 2012"
"vendredi 15 juin 2012" => "Friday 15th of June 2012"

Hibernate 3.6.8.Final
JSF 2.0
JBoss 5.1.0.GA
Java 6

Thanks.

3
  • 4
    Timezone of the machine that is producing this result? Commented Jun 15, 2012 at 16:27
  • GMT +1 (JBoss side) , GMT +0200 (Postgresql) Commented Jun 15, 2012 at 16:29
  • 3
    Also "jeudi" is "Thursday", not "Tuesday." Commented Jun 15, 2012 at 16:29

3 Answers 3

1

It's showing you just one day ahead of what you expect. Reason might be server time which is on another time zone I guess. Anyways the below code is working fine:

SimpleDateFormat sdf = new SimpleDateFormat("EEEE dd MMMM yyyy", Locale.FRENCH);
System.out.println(sdf.format(new Date()));
Sign up to request clarification or add additional context in comments.

Comments

1

After searching, it turns out that I had two main options. Either I set the time zone through Hibernate or JSF.

Option 1 : Hibernate
I could change access type to Property. So in the setter, I would adjust the timestamp value to the right time zone. Another solution would be to create a custom Hibernate User Type.

Full details with code here : Mapping Dates and Time Zones with Hibernate, Part 2: Few Solutions

Option 2 : JSF
Last option, I either create a custom converter in JSF or more simply, I use the timeZone attribute of f:convertDateTime.

This how I did it :

<h:outputText value="#{row.date}">
    <f:convertDateTime pattern="EEEE dd MMMM yyyy" locale="fr_FR" type="date" timeZone="Europe/Paris" />
</h:outputText>

All my dates are correct now !

Source (in french) : Comment utiliser le timezone du compensant JSF convertDateTime

Comments

0
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd MMMM yyyy zzzz G", Locale.FRENCH);

try this

also printing out a date will automatically print formatted date text in machine time zone.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.