Java DatePicker - how to set format date

Hi,
How to set DatePicker DateFormat that is show when value is inside the field? See screenshot. I try “setLocale” method but value doesn’t change. I need DD.MM.YYYY format. Thank you.
Regards,
Matic
17295589.png

At least the demo looks like setLocale should work: https://vaadin.com/components/vaadin-date-picker/java-examples (see the “Date picker with customize locales” example).

Hi,
Thank you - it was my mistake. I have use Locale.GERMAN and not Locale.GERMANY

Hi,
I am using following code:

final com.vaadin.flow.component.datepicker.DatePicker date = new com.vaadin.flow.component.datepicker.DatePicker();
date.setLocale(java.util.Locale.UK);

Output in DatePicker after selecting a date is: 02/05/2019 

>>> OK

Now I change the locale to: date.setLocale(java.util.Locale.GERMANY);

Output in DatePicker after selecting a date is: 2.5.2019 

>>> WRONG

I need the output: 02.05.2019 for locale GERMANY

How can I change this? Is there a way to se a custom date pattern into DatePicker?

Thank you very much,
Thomas

Hi, I got the same problem as Thomas. It would be good to have the possibility to set a custom pattern or at least to choose an alternative that presents leading zeros for day/month values < 10.

Hi Lutz. There is an enhancement issue open for setting a custom pattern for DatePicker, please go +1 the issue https://github.com/vaadin/vaadin-date-picker-flow/issues/156 because we are actively looking at which issues are the most popular and try to prioritize those.

Hi, using Vaadin 14,

  1. which SQL Format (Mysql) may we bind with DatePicker?
  2. which SQL Format (Mysql) may we bind with DateTimePicker?

Many thanks in advance :wink:

You can use any type you want, as long as you use [suitable Converters]
(https://vaadin.com/docs/v14/flow/binding-data/tutorial-flow-components-binder-validation.html#converting-user-input) with the components.

Could you provide an example?
I just want to store a date in the database, many thanks

The DatePicker’s default value type is LocalDate and the DateTimePicker’s value type is DateTimePicker. Which is the type you want to convert them to? Is it java.sql.Date or something else?

I’m using JPA entity, with property f.e. startDate

private java.util.Date startDate;

@Temporal(TemporalType.DATE)
public Date getStartDate() {
	return startDate;
}

public void setStartDate(Date startDate) {
	this.startDate = startDate;
}


DatePicker datePicker = new DatePicker();
datePicker.setLabel("Select a start date");
// datePicker.setPlaceholder("Select a start date");
datePicker.setClearButtonVisible(true);

I would like to bind it

Okay, so regular old java.util.Date? There you can just use a LocalDateToDateConverter:

        Binder<Person> binder = new Binder<>();
        DatePicker datePicker = new DatePicker();
        binder.forField(datePicker).withConverter(new LocalDateToDateConverter())
                .bind(Person::getStartDate, Person::setStartDate);

Many Thansk Olli, it’s working perfectly :wink: