Format date within View in ASP.NET Core MVC

前端 未结 9 2137
借酒劲吻你
借酒劲吻你 2020-12-30 09:51

I have problem in regarding with converting the datetime to date using a model.

Model from Class Library

public partial class LoanCo         


        
相关标签:
9条回答
  • 2020-12-30 10:39

    If when defining in model does not work, you can use inside your view file:

    @String.Format("{0:dd/MM/yyyy}",ViewBag.TerminoDaAvaliacao)
    

    This ViewBag contains a DateTime value. The time disapears with this format definition. It is not necessary to change DateTime by Date inside the Model file definition.

    0 讨论(0)
  • 2020-12-30 10:45

    I think it is a bug for dateformat escape chars on dotnet core. None of above solutions worked for me. Only this method solved my problem. why does DateTime.ToString("dd/MM/yyyy") give me dd-MM-yyyy?

    [DisplayFormat(DataFormatString = "{0:dd'/'MM'/'yyyy}", ApplyFormatInEditMode = true)]
    

    or

    <input asp-for="DateProperty" asp-format="{0:dd'/'MM'/'yyyy}">
    
    0 讨论(0)
  • 2020-12-30 10:48

    This might be extremely helpful sometimes,

    <input asp-for="DateProperty" asp-format="**@Model.DateProperty.ToString($"{0:dd/MM/yyyy}")**">
    
    0 讨论(0)
提交回复
热议问题