1

I'm new to Blazor and I'm working on a Blazor Webassembly project where I need to format the DateTime input as "dd/MM/yyyy".

I already tried this:

This is what I have:

<InputDate @bind-Value="@Model.Date1" class="form-control"/>
<InputDate @bind-Value="@Model.Date2" class="form-control"/>
<InputDate @bind-Value="@Model.Date3" class="form-control"/>

The Model:

public class Model
{
    public DateTime? Date1{ get; set; }
    public DateTime? Date1{ get; set; }
    public DateTime? Date3{ get; set; }
}

Also tried this:

<input type="date" @Bind="Model.Date1" @Bind:format="dd-MM-yyyy" class="form-control"/>

But nothing changed.

The result

The question is: How can I format the InputDate in "dd/MM/yyyy"?

Palle Due
  • 5,929
  • 4
  • 17
  • 32
MammaMia
  • 13
  • 5
  • 3
    Browsers display dates using local language/region settings - don't try to force a specific format yourself. – Mister Magoo May 03 '22 at 10:47
  • I agree with @MisterMagoo I live in Australia this is the default I see without doing anything in blazor. A lot of developers want to see them all and be selectable. The client/end user will just set the browser to their specific culture needs and thats it. Why force them to do it again inside your app? – Brian Parker May 03 '22 at 10:53
  • 1
    It's not possible to change the date format because inputDate uses an html input type="date" which always uses the current locale. Yet, there are open source and commercial components that will allow you to set the format, e.g., [SyncFusion DatePicker](https://www.syncfusion.com/blazor-components/blazor-datepicker) – Yogi May 03 '22 at 11:47

0 Answers0