I recently upgraded to windows 10 - and I'm now seeing some rather unexpected changes in the output of a date when using the "tt" format specifier.
Here's some code that demonstrates the issue:
using System.IO;
using System;
using System.Globalization;
using System.Threading.Tasks;
class Program
{
static void Main()
{
var cultures = new string[] {null, "en-NZ", "en-US", "en-AU", "en-GB"};
foreach (var culture in cultures) {
if (culture != null) {
var c = CultureInfo.GetCultureInfo(culture);
System.Threading.Thread.CurrentThread.CurrentCulture = System.Threading.Thread.CurrentThread.CurrentUICulture = c;
}
DateTime dt = new DateTime(2015, 1, 2, 3, 4, 5, DateTimeKind.Utc);
Console.WriteLine("selection: {0} CurrentThread.CurrentCulture.Name: {1} CurrentThread.CurrentUICulture.Name: {2} Value: {3}",
culture ?? "ambient",
System.Threading.Thread.CurrentThread.CurrentCulture.Name,
System.Threading.Thread.CurrentThread.CurrentUICulture.Name,
dt.ToString("hhh:mm tt"));
}
}
}
The output in previous versions of windows was:
selection: ambient CurrentThread.CurrentCulture.Name: en-NZ CurrentThread.CurrentUICulture.Name: en-NZ Value: 03:04 a.m.
selection: en-NZ CurrentThread.CurrentCulture.Name: en-NZ CurrentThread.CurrentUICulture.Name: en-NZ Value: 03:04 a.m.
selection: en-US CurrentThread.CurrentCulture.Name: en-US CurrentThread.CurrentUICulture.Name: en-US Value: 03:04 AM
selection: en-AU CurrentThread.CurrentCulture.Name: en-AU CurrentThread.CurrentUICulture.Name: en-AU Value: 03:04 AM
selection: en-GB CurrentThread.CurrentCulture.Name: en-GB CurrentThread.CurrentUICulture.Name: en-GB Value: 03:04 am
And in windows 10:
selection: ambient (windows 10) CurrentThread.CurrentCulture.Name: en-NZ CurrentThread.CurrentUICulture.Name: en-US Value: 03:04 a.m.
selection: en-NZ CurrentThread.CurrentCulture.Name: en-NZ CurrentThread.CurrentUICulture.Name: en-NZ Value: 03:04 AM
selection: en-US CurrentThread.CurrentCulture.Name: en-US CurrentThread.CurrentUICulture.Name: en-US Value: 03:04 AM
selection: en-AU CurrentThread.CurrentCulture.Name: en-AU CurrentThread.CurrentUICulture.Name: en-AU Value: 03:04 AM
selection: en-GB CurrentThread.CurrentCulture.Name: en-GB CurrentThread.CurrentUICulture.Name: en-GB Value: 03:04 AM
In both cases this code was compile win Visual Studio 2013 targeting .Net Framework 4.5
Does anyone know why the behavior has changed - and why in windows 10 it appears setting any culture on a thread specifically changes the output of AM/PM to be formatted as "AM" / "PM" not what is normally outputted for that culture?