• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: 12 hr vs 24 hr time display
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 12 hr vs 24 hr time display


  • Subject: Re: 12 hr vs 24 hr time display
  • From: Sandor Szatmari <email@hidden>
  • Date: Tue, 03 Jan 2017 21:02:29 -0500

Alex,

> On Jan 3, 2017, at 19:51, Alex Zavatone <email@hidden> wrote:
>
>
>> On Jan 3, 2017, at 3:02 PM, Sandor Szatmari wrote:
>>
>> Gary,
>>
>>> On Jan 3, 2017, at 14:52, Gary L. Wade <email@hidden> wrote:
>>>
>>> Is there a problem with using +[NSDateFormatter localizedStringFromDate:dateStyle:timeStyle:]? Depending on your needs, you might also consider +[NSCalendar autoupdatingCurrentCalendar].
>>
>> I am looking for detecting whether or not the system defaults to 12 or 24 hr time.  The obj-c method I'm already 'parsing', -dateFormatFromTemplate:::, returns a template string with well defined formatting tokens that are easy to detect.  Plus they directly reflect the user's Locale & Region settings.
>
> I'd expect that would be a function of the language and the locale, possibly just the locale.  Do you care what it defaults to or what it's currently set to?

That's correct and I only care so far as I can determine it as being either 12 or 24.

The relevant methods are, -dateFormatFromTemplate::: returns a format string which -localizedStringFromDate:dateStyle:timeStyle: consumes to produces a human readable Date string.  I am not doing the second step described here.  Producing he actual string the view is separate from this state stored in my model.

The relevant bits are: -dateFormatFromTemplate::: with a template of 'j' returns the default format string for the Locale passed as the Locale argument.  I am passing [NSLocale currentLocale].

It is my understanding that any Locale which supports the 12 hr time format must represent the AM/PM as 'a' in the format string provided to -localizedStringFromDate:dateStyle:timeStyle:.  So therefore the presence of 'a' indicates that the Locale is configured for 12 hr time.  Otherwise, it's 24 hr time.  What I am relying on is the behavior of -dateFormatFromTemplate::: when passed the 'j' template.  This behavior is documented here http://www.unicode.org/reports/tr35/tr35-31/tr35-dates.html#Date_Format_Patterns.  It specifically mentions using 'j' to determine the presence AM/PM or not.  i.e. 12 or 24 hr time.

Might some Locales only support 12 or 24?  Maybe, maybe not.  But if I decide to only rely on the setting from Locale & Region and my interpretations are good this should not matter.  The user will never see 12 or 24 for locales that do not support them.
The specific section is http://www.unicode.org/reports/tr35/tr35-31/tr35-dates.html#Day_Period_Rules.

Thanks,
Sandor

>
> - Z
>
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Follow-Ups:
    • Re: 12 hr vs 24 hr time display
      • From: Alex Zavatone <email@hidden>
References: 
 >12 hr vs 24 hr time display (From: Sandor Szatmari <email@hidden>)
 >Re: 12 hr vs 24 hr time display (From: Sandor Szatmari <email@hidden>)
 >Re: 12 hr vs 24 hr time display (From: "Gary L. Wade" <email@hidden>)
 >Re: 12 hr vs 24 hr time display (From: Sandor Szatmari <email@hidden>)
 >Re: 12 hr vs 24 hr time display (From: Alex Zavatone <email@hidden>)

  • Prev by Date: Re: 12 hr vs 24 hr time display
  • Next by Date: Re: 12 hr vs 24 hr time display
  • Previous by thread: Re: 12 hr vs 24 hr time display
  • Next by thread: Re: 12 hr vs 24 hr time display
  • Index(es):
    • Date
    • Thread