determine if “24-hour clock” setting is set

。_饼干妹妹 提交于 2019-11-28 12:37:53
user994597

The system clock type can be retrieved using:

string clockType = Windows.System.UserProfile.GlobalizationPreferences.Clocks.FirstOrDefault();

This will return the string 24HourClock if the 24 hour setting is on in the device settings or 12HourClock if the setting is off.

On the back of Dennis' answer, you should be able to determine 24-hour time using String.Contains:

bool is24HourTime = DateTimeFormatInfo.CurrentInfo.ShortTimePattern.Contains("H");

The DateTimeFormatInfo.CurrentInfo.ShortTimePattern way of getting the hour is tied to the culture, and not to the option showing whether 24-hour time is enabled or not. So you will get h:mm tt for English (United States) and HH:mm for German (Germany).

At this moment, you cannot get this system setting.

Tetsuro Takao

For japanese developers, please note.

DateTimeFormatInfo.CurrentInfo.ShortTimePattern in the culture ja-JP will return the same string H:mm, regardless of if the phone setting for 24-Hour time is enabled or not.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!