检测12/24小时时间显示设置

本文关键字:显示 设置 时间 24小时 检测 | 更新日期: 2023-09-27 18:19:43

在手机中选择某些地区格式时,您可以选择日期+时间选项,您可以在其中选择时间是否应以24小时格式显示。

有没有办法让我读懂这个设定?我希望基于此设置显示应用程序中的时间?

提前谢谢。

检测12/24小时时间显示设置

也可以使用此链接下载各种C#| VB Windows智能手机代码全球化代码和下载

此链接是MSDN下载。如果您正在为Windows智能手机进行编码,下载还应该帮助您做其他事情

 // set this thread's current culture to the culture associated with the selected locale
            CultureInfo newCulture = new CultureInfo(cul);
            Thread.CurrentThread.CurrentCulture = newCulture;
            CultureInfo cc, cuic;
            cc = Thread.CurrentThread.CurrentCulture;
            cuic = Thread.CurrentThread.CurrentUICulture;
            // display the culture name in the language of the selected locale
            regionalFrmt.Text = cc.NativeName;
            // display the culture name in the localized language
            displayLang.Text = cuic.DisplayName;
            // display the date formats (long and short form) for the  current culuture  
            DateTime curDate = DateTime.Now;
            longDate.Text = cc.DateTimeFormat.LongDatePattern.ToString() + " " + curDate.ToString("D");
            shortDate.Text = cc.DateTimeFormat.ShortDatePattern.ToString() + "   " + curDate.ToString("d");
            // display the time format (long form) for the current culture
            longTime.Text = cc.DateTimeFormat.LongTimePattern + "   " + curDate.ToString("T");

根据DateTimeFormatInfo文档,"当时钟设置为24小时时,DateTimeFormatInfo.ShortTimePattern值不会更改。属性值应变为"h:mm",但保留为"hmm-tt",其中tt为AM或PM。"

看起来这是一个错误,希望能在WindowsPhone8中修复。

无论如何,为了回答你的问题。。。你可以使用这个:

string pattern = CultureInfo.CurrentCulture.DateTimeFormat.LongTimePattern.Replace(":ss", "");

这是从Silverlight工具包中获取的。