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?
Terrestrial Time (TT) is a modern astronomical time standard defined by the International Astronomical Union, primarily for time-measurements of astronomical observations made from the surface of Earth.
The "fff" custom format specifier represents the three most significant digits of the seconds fraction; that is, it represents the milliseconds in a date and time value.
1. Display current date and time in 12 hour format with AM/PM. There are two patterns that we can use in SimpleDateFormat to display time. Pattern “hh:mm aa” and “HH:mm aa”, here HH is used for 24 hour format without AM/PM and the hh is used for 12 hour format with AM/PM.
You may want to look at "Culture Data Shouldn't Be Considered Stable" http://blogs.msdn.com/b/shawnste/archive/2005/04/05/405694.aspx
One bit is that we started leveraging CLDR (Common Locale Data Repository, http://cldr.unicode.org) for many locales to better align with the industry standards. You may have noticed that there are quite a few additional locales we now have data for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With