I’m working on a Windows phone project where the time is being displayed, and even though I’m in America, I prefer 24 hour formatted time. Most around me don’t, and as a result I’ve become sensitive to ensuring that someone can choose to customize this as they want. Normally in .Net you would simply use the following code:

But things aren’t always so simple. Without going into details for my use case, it is necessary to check if a user has selected 24 hour or 12 hour time. This setting is available in the phone settings –> date+time –> 24 hour clock. However the Windows phone api doesn’t allow us to directly check this setting. It does however directly effect the outputs of others. To determine if the time is in 12 or 24 hour format we can simply:

You can see from the examples below that by changing the setting, we can properly detect what the setting is. This code is also influenced by region and culture. However, you can still know which format the clock is in and adjust your logic the way you need to.

FormatDetection24 FormatDetection12

Leave a Reply
Your email address will not be published.
  • ( will not be published )