user1075940
user1075940

Reputation: 1125

Wrong date format displayed dd-MM-yyyy instead of dd/MM/yyyy

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

Answers (2)

Rahul Tripathi
Rahul Tripathi

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

user1075940
user1075940

Reputation: 1125

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

Upvotes: 3

Related Questions