I have a Razor page that takes dates as input and displays the dates that have been entered in a table.
To input the date, I use <input type="date" />
which MDN states:
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.
This works as described, showing the date in the User’s choice date format. I can even change my Windows settings, reload the page, and see what I set it to.
The trouble comes from trying to convert the yyyy-MM-dd dates I have stored to the user selected format.
I have tried managing the display format at the server with C# date.ToShortDateString()
which looked right on localhost, but displayed the CultureInfo from the server when I deployed to Dev.
I have also tried managing the display format as a last step with JavaScript date.toLocaleDateString()
which seems to just pick the standard MM/dd/yyyy for en-US.
This is 2023, the browser knows what the user has selected, it is using with the <input>
. How can I format my dates the same? (Preferably without extra libraries that are no longer supported.)