How Can i keep a fix Standard Date Format regardless of any Locale

345 Views Asked by At

I am trying to keep the Date format to Standard locale "en" regardless of whatever the locale is but it's changing as the locale get change. I am using thymeleaf 3 , for simple text display field i fixed it as note* i am using java.util.date

<td th:text="${#temporals.format(T(java.time.LocalDate).of(#dates.year(birthdate), #dates.month(birthdate), #dates.day(birthdate)), 'dd-MM-yyyy', new java.util.Locale('en', 'EN'))}"></td>
but the problem i am facing is during form updating when the locale is not set to standard("en"). then the input field doesn't show up the value and just show the date format .

<input type="date" class="form-control"  required="required" th:field="*{{birthDate}}" name="birthDate">
<input type="date" class="form-control" required="required" th:field="*{{registrationDate}}" name="registrationDate">
And during editing the form i get my dates like this enter image description here

any help would be appreciated ! thanks

1

There are 1 best solutions below

0
On

I fixed it for the input fields too

<input type="date" class="form-control" id="txtDateOfBirthAdd" required="required"
                                 
th:value="${employee.birthDate}?${#temporals.format(T(java.time.LocalDate).of(#dates.year(employee.birthDate), #dates.month(employee.birthDate), #dates.day(employee.birthDate)), 'yyyy-MM-dd', new java.util.Locale('en', 'EN'))}:''"                                  
                                    name="birthDate"
                                    placeholder="Date of Birth">

now i have fixed date pattern no matter whatever the locale is . .