Reputation: 1125
I am trying to display date in this format dd/MM/yyyy
Model addnotations
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime Time {get;set;}
In view
@Html.DisplayFor(model => model.Time)
instead I am getting date in format dd-MM-yyyy
I have also tried dd.MM.yyyy
which works fine.Anything works fine except desired result.
Upvotes: 1
Views: 1706
Reputation: 172378
You may try this:-
[DisplayFormat(DataFormatString = "{0:dd'/'MM'/'yyyy}", ApplyFormatInEditMode = true)]
public DateTime myDate { get; set; }
then use it like:
@Html.DisplayFor(model => model.Time)
Upvotes: 0
Reputation: 1125
Here is correct format
[DisplayFormat(DataFormatString = "{0:dd'/'MM'/'yyyy}", ApplyFormatInEditMode = true)]
Upvotes: 3