简体   繁体   中英

Why is the date format different for the same culture on different computers or OS?

I have problem with date formate while hosting site which is developed using C# .net MVC .

In my development machine( OS:Windows 7, .net Framework 4.5 ) date formate for Spanish-Panama(es-PA) is mm/dd/yy and in server machine( OS:Windows 8, .net Framework 4.5 ) it is giving d/m/yy format for same culture.

I checked it with by using simple console application.

public static void Main()
{
    DateTime dt = DateTime.Now;
    Thread.CurrentThread.CurrentCulture = new CultureInfo("es-PA");

    Console.WriteLine(dt.ToString("d"));

    Console.ReadLine();
}

Output on development machine is: 10/08/2015

Output on server machine is : 8/10/15

I also checked by changing Language and Regional but in both machine default format is different.

Why format is different in different machine for same culture? Is there any solution for this?

Why format is different in different machine for same culture?

Because formats are updated over time, in different OS releases and in patches/hotfixes. .NET is fetching the format from the OS (I believe, anyway), so it's the OS that's the source of the difference - as you've seen in the regional settings.

Is there any solution for this?

Check that both machines are up to date with Windows Update, and possibly check for any hotfixes available for this. Otherwise, you could always manually update the one you want to change, but obviously that's far from ideal.

It's possible that Windows 8 just has more up-to-date information than Windows 7 in a way that isn't going to be addressed by Windows update :(

Cultures have multiple accepted formats. The thread gets it culture (and thus format) from the account the thread is executing as.

For example if you are running IIS express on your dev machine (IIS express uses the windows users account for ASP.NET worker process) you can change to another valid format, for that same culture in windows and this would now be the outputed format for your web application.

It is hard to give a solution for a non issue. It is still the same date, and actually displays the set culture properly.

However if you want to force a format, you should be able to do that by setting for example CurrentCulture.DateTimeFormat.ShortDatePattern

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM