Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 680
Mehul Patel Avatar asked Oct 08 '15 18:10

Mehul Patel


People also ask

What time and date format does the computer follow?

The system bases system time on coordinated universal time (UTC). UTC-based time is loosely defined as the current date and time of day in Greenwich, England.

What date format is used worldwide?

The ISO 8601 format YYYY-MM-DD (2022-11-01) is intended to harmonize these formats and ensure accuracy in all situations. Many countries have adopted it as their sole official date format, though even in these areas writers may adopt abbreviated formats that are no longer recommended.

What is the standard date format for programming?

YYYY-MM-DD where YYYY is the year in the usual Gregorian calendar, MM is the month of the year between 01 (January) and 12 (December), and DD is the day of the month between 01 and 31.


1 Answers

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 :(

like image 108
Jon Skeet Avatar answered Nov 12 '22 01:11

Jon Skeet