下午还是24小时制

下午还是24小时制

本文介绍了如何确定当前的文化/地区使用的是上午/下午还是24小时制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要确定当前的文化/区域设置为使用am/pm时间还是24小时制.

I need to determine if the current culture/locale is set to use am/pm time or 24-hour time.

起初我以为我可以这样做:

At first I thought I could do this:

bool time24Hour = Thread.CurrentThread.CurrentCulture.DateTimeFormat.AMDesignator == "";

但是我随后在该线程上阅读了关于最后答案的评论工作.

But then I read the comments on the last answer on this thread Get just the hour of day from DateTime using either 12 or 24 hour format as defined by the current culture which seems to imply this won't work.

我想我可以格式化任意时间,然后分析结果,但是肯定有一种更简单的方法吗?

I guess I could format an arbitrary time, and then analyze the results, but surely there's a simplier way?

另请参阅下面的评论-我只想确定两个预格式化的常量字符串中包含哪一个小时列表,我应该选择其中之一,并希望避免出现许多不必要的扭曲-我只需要是/否答案即可是上午/下午文化还是24小时文化.

See also my comment below - I just want to determine which one of two pre-formatted constant strings containing lists of hours I should select, and hope to avoid a lot of unnecessary contortions - I just need a yes/no answer as to whether this is an am/pm culture or a 24-hour culture.

该程序是WinForms程序,如果有帮助的话.

The program is a WinForms program, if that is of any help.

推荐答案

尝试检查 DateTimeFormat.ShortTimePattern 包含 H .如果是这样,则系统正在使用24小时制

Try checking if DateTimeFormat.ShortTimePattern contains H. If it does, the system is using 24-hour time

这篇关于如何确定当前的文化/地区使用的是上午/下午还是24小时制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 05:35