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…
Asked
Active
Viewed 133 times
3
-
2Probably there's an open issue for this: https://github.com/vaadin/flow-components/issues/911 – Hawk Jun 13 '21 at 09:34
-
Thank you very much, @Hawk, I subscribed to the issue. There are some useful hints in the comments. – McPringle Jun 14 '21 at 08:31
1 Answers
3
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");

Simon Martinelli
- 34,053
- 5
- 48
- 82
-
Nice! But to replace the `DateTimePicker`, I had to break my code up to use two components instead of one. That's not a big deal. :-) – McPringle Jun 14 '21 at 08:32
-
-
My entity has a `LocalDateTime` and with the `DateTimePicker`I can bind that entity property directly, because the `DateTimePicker` handles both: date and time. The `EnhancedDatePicker` only handles `LocalDate`, not the time. So I had to rewrite the code a bit. Not a big deal. – McPringle Jun 14 '21 at 08:48
-
2If you have Date and Time we will have soon an EnhancedDateTimePicker ;-) Wait a few days. – Simon Martinelli Jun 14 '21 at 09:23
-