Gần đây tôi đã nâng cấp lên cửa sổ 10 - và bây giờ tôi thấy một số thay đổi bất ngờ trong đầu ra của một ngày khi sử dụng định dạng "tt".Đầu ra của thời gian (AM/PM) đã thay đổi trong Windows 10 khi sử dụng DateTime.ToString ("tt")
Dưới đây là một số mã đó chứng tỏ vấn đề:
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"));
}
}
}
Sản lượng trong các phiên bản trước của cửa sổ là:
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
Và trong các cửa sổ 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
Trong cả hai trường hợp mã này đã được biên dịch giành chiến thắng Visual Studio 2013 nhắm mục tiêu .Net Framework 4.5
Có ai biết tại sao hành vi đã thay đổi không - và tại sao trong cửa sổ 10 nó xuất hiện thiết lập bất kỳ nền văn hóa nào trên một chủ đề cụ thể thay đổi đầu ra của AM/PM thành định dạng "AM"/"PM". nền văn hóa đó?
Mã của bạn đang chạy tốt trên máy tính Windows10/VS2015/4.5. – vendettamit
Bạn có cài đặt các tệp ngôn ngữ Windows 10 cho tất cả các nền văn hóa bạn sử dụng ở đây không? –
Tôi có tất cả các tính năng ngôn ngữ tùy chọn được cài đặt cho en-GB và en-US ... en-AU và en-NZ chỉ là ngoài hộp (nhưng tôi có chúng được định cấu hình làm ngôn ngữ mà tôi có thể đọc và viết bằng cửa sổ 10). Điều này chắc chắn là một hồi quy trong hành vi mà tôi nghĩ - cũng như tôi đã hiểu, dữ liệu CultureInfo được tải từ các cuộc gọi nội bộ, nhưng đến từ dữ liệu luôn có sẵn trong các cửa sổ, ví dụ:thông tin giống với hộp thoại cài đặt ngày và giờ khi bạn chuyển đổi giữa các quốc gia. – Bittercoder