如何使用 blazor <InputDate /> 标记使用本地文化格式化日期

Die*_*ter 5 asp.net-core blazor blazor-server-side

我在 Blazor 应用程序中使用该标签。但是如何使用我自己的文化来格式化日期?

            <InputDate class="form-control" @bind-Value="@ValidDate" @bind-Value:culture="nl-BE" @bind-Value:format="dd/MM/yyyy" />  
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

问候迪特

Pet*_*ris 9

答案是@bind-Value:format,像这样

@page "/"

<EditForm Model="@CurrentPerson">
    <InputDate @bind-Value="@CurrentPerson.DateOfBirth" @bind-Value:format="dd/MM/yyyy"/>
</EditForm>

@code
{
    Person CurrentPerson = new Person();
    public class Person
    {
        public DateTime DateOfBirth { get; set; } = DateTime.Now;
    }
}
Run Code Online (Sandbox Code Playgroud)

还可以选择使用bind-Value:culture.

  • 使用 `@bind-Value:format="yyyy/MM/dd"` 对我没有任何影响。输入元素中的日期仍采用 dd/MM/yy 格式。 (12认同)