3

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…

McPringle
  • 1,939
  • 2
  • 16
  • 19
  • 2
    Probably 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 Answers1

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