How to get leading zeros displayed in the Vaadin DateTimePicker component?

Viewed 96

In my Vaadin Flow application, I'm using the Vaadin DateTimePicker component. If I select a date, it will be displayed without the leading zeros (e.g. "4.7.2021"). I would like the component to display the leading zeros (e.g. "04.07.2021"), but I could not find an API call to do so. Locale is Switzerland. Any ideas? I guess I'm missing a really easy solution to this all-day-problem…

1 Answers

You should use the EnhancedDatePicker https://vaadin.com/directory/component/enhanced-datepicker

There you can set pattern and even parsers. For example:

// how the date should be formatted
datePicker.setPattern("dd.MM.yyyy);

// allowed formats to enter the date
datePicker.setParsers("ddMMyy", "ddMMyyyy", "dd.MM.yy", "dd.MM.yyyy"); 
Related