By default JSF using GMT timezone to convert the date into display format. I did Google search about this issue, found no simple solution to solve this problem.

Here is a simple solution where you can provide your custom date time converter. I like this solution because it fixes GMT date/time issue across the application.

1) Write a new custom converter by extending existing DateTimeConverter class.

package com.company.project.converter;

import java.util.TimeZone;

import javax.faces.convert.DateTimeConverter;

public class CustomDateTimeConverter extends DateTimeConverter {

public CustomDateTimeConverter() {
super();
setTimeZone(TimeZone.getDefault());
// here you can set your custom date pattern for your project
// setPattern("M/d/yy");
}

}

Bind your new converter as default converter for object of type java.util.Date

<converter>
<converter-for-class>java.util.Date</converter-for-class>
<converter-class>com.company.project.converter.CustomDateTimeConverter</converter-class>
</converter>

Related Articles

13 responses to “JSF default timezone and date pattern”

  1. Paulo

    Após mais de um dia tendo problemas para inserir datas utilizando o (que estava armazenando as datas com um dia a menos do que a digitada) e tentar diversas outras soluções propostas na internet, utilizei a solução aqui proposta e resolvi meu problema. Muito obrigado!!!

  2. Paulo

    utilizando o … f:ConvertDateTime (…

  3. Anonymous

    thanks

  4. Anonymous

    nice

  5. Raphael

    In JSF 2 you can define this in web.xml to use the system timezone:

    javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE
    true

  6. YurZ

    Thanks Raphael, javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE was exactly what I was looking for.

  7. Jutus Herz

    You talk about the pattern. But, sometimes, the date is simply dd/MM/yyy (no time), and sometime have time. How we can handle it?

  8. Michel

    Using jsf 1.2 and icefaces 1.8.2_7, I had to register the custom converter using id “javax.faces.DateTime” in order to enable it with .

  9. Michel

    Using jsf 1.2 and icefaces 1.8.2_7, I had to register the custom converter using id “javax.faces.DateTime” in order to enable it with f:convertDateTime tags.

  10. right using javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE define timeZone, but who define the format unused tag f:convertDateTime, can you define this in web.xml a configuration?
    I’m from Ecuador, sorry for the bad English…

  11. Anonymous

    This is quite helpful, thanks a lot, worked perfectly!

Leave a comment

I’m Venkat

A passionate software engineer with over 20 years of experience in the tech industry. Welcome to my digital playground where I share my journey through the ever-evolving world of software development and cloud technologies!