0

I googled for a way to change the format of the HTML date input value from mm/dd/yyyy to the Italian way "gg/mm/aaaa".

I know that it is enough to change the browser language to Italian but our client asked to force the default value to the italian format "gg/mm/aaaa". Is there a way using code?

HTML:

<table>
    <tr>
        <td class="searchLabel">Departure Date:</td>
        <td><input type="date" id="departureDate" ></td>
    </tr>
</table>

JS:

var departureDate = document.getElementById("departureDate").value;

expected output

Onixy
  • 35
  • 1
  • 5

1 Answers1

0

Have a look at : https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/date#additional_attributes

It says:

Note: The displayed date format will differ from the actual value — the displayed date is formatted based on the locale of the user's browser, but the parsed value is always formatted yyyy-mm-dd.

Muhammed Fazil K
  • 43
  • 1
  • 1
  • 5
  • this means isn't possible to change the format via code? I'm not asking for "dd-mm-yyyy" from "yyyy-mm-dd" but to "gg-mm-aaaa" we can even suppose to have "bla-bla-bla"... maybe something that convert the default date to string and change it via js? – Onixy Nov 30 '22 at 11:20