Chris Sainty
Chris Sainty

Reputation: 8521

MVC 3 application date format issue

Ok this is really driving me nuts, dates in my MVC 3 application will only show in American date format i.e. mm/dd/yy.

I have checked my systems location setting and everything is set to the UK, I've checked the globalisation settings in IIS and set those to United Kingdom. I have also added the following to my applications web.config:

<globalization uiCulture="en-GB" culture="en-GB" />

But still dates show in mm/dd/yy format! I have tried to format the dates in my views using .ToString() as follows:

@location.DateFrom.ToString("dd/MM/yyyy")

Still American format! Can someone please shed some light on this as its literally driving me insane, I can't even think of what else to change. Any help would be greatly appreciated, cheers.

Upvotes: 0

Views: 315

Answers (1)

Oded
Oded

Reputation: 498904

This will certainly format for "en-GB":

@location.DateFrom.ToString("dd/MM/yyyy", CultureInfo.GetCultureInfo("en-GB"))

You need to check the Thread.CurrentCulture and Thread.CurrentUICulture to see what they are returning.

Upvotes: 1

Related Questions