在用户计算机上检测24对12小时时钟

时间:2015-02-24 12:55:03

标签: c# datetime time

我正在寻找一种更好的方法来检测当前的PC是使用24小时制还是12小时制

DateTimeFormatInfo.ShortTimePattern Property声明,如果时间为12小时,tt将作为ShortTimePattern的一部分返回,但此解决方案只会让我感到麻烦。

if (System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortTimePattern.IndexOf("tt") > -1)
  {
   TimeControl.clock24 = false;
  }
else
 {
  TimeControl.clock24 = true;
 }


/* This example produces the following output.
    CULTURE    PROPERTY VALUE
     en-US     h:mm tt
     ja-JP     H:mm
     fr-FR     HH:mm
*/

我正在寻找一种方法,不包括扫描日期时间表,因为用户可以更改日期时间模式。

  

文化的时间模式可以包含任何内容(用户可以   甚至创建一个自定义文化,其中ShortTimePattern是" \ hello"   然后DateTime.ToString()将返回"你好"任何时候)。

虽然CultureInfo.CurrentCulture.DateTimeFormat.AMDesignator在某些情况下有效,但它并不适用于H vs h

0 个答案:

没有答案