Preferred hour format for locale in date format template











up vote
1
down vote

favorite












When generating date formats from a template with Foundation's DateFormatter for the Locale "de", like this:



let locale: Locale = Locale(identifier: "de")
let format = DateFormatter.dateFormat(fromTemplate: "dMMMyGhhmmss",
options: 0,
locale: locale)


I always get this format:



d. MMM y G, h:mm:ss a


which renders



17. Nov. 2018 n. Chr., 8:30:20 PM


The 'PM' part is unusual for Locale "de", but it is my understanding that this method also takes user preferences into account. Is that correct?



I played around with the settings in System Preferences, e.g. switching to 24-hour clock, but nothing I changed had any effect. Do I have to restart something for the changes to take effect?



Can someone explain to me what's going on?










share|improve this question
























  • Change the h to H in your template.
    – rmaddy
    Nov 17 at 20:37










  • @rmaddy Then it also uses the 24-hour format for locale "en". However, your comment prompted me to check the spec again and I found that I could replace h with j, which causes the format generator to pick h or H depending on the locale.
    – mistercake
    Nov 17 at 20:46












  • Good find. I always forget about j. That should be used with a template like this. You should post your own answer explaining why j is the correct solution.
    – rmaddy
    Nov 17 at 20:49















up vote
1
down vote

favorite












When generating date formats from a template with Foundation's DateFormatter for the Locale "de", like this:



let locale: Locale = Locale(identifier: "de")
let format = DateFormatter.dateFormat(fromTemplate: "dMMMyGhhmmss",
options: 0,
locale: locale)


I always get this format:



d. MMM y G, h:mm:ss a


which renders



17. Nov. 2018 n. Chr., 8:30:20 PM


The 'PM' part is unusual for Locale "de", but it is my understanding that this method also takes user preferences into account. Is that correct?



I played around with the settings in System Preferences, e.g. switching to 24-hour clock, but nothing I changed had any effect. Do I have to restart something for the changes to take effect?



Can someone explain to me what's going on?










share|improve this question
























  • Change the h to H in your template.
    – rmaddy
    Nov 17 at 20:37










  • @rmaddy Then it also uses the 24-hour format for locale "en". However, your comment prompted me to check the spec again and I found that I could replace h with j, which causes the format generator to pick h or H depending on the locale.
    – mistercake
    Nov 17 at 20:46












  • Good find. I always forget about j. That should be used with a template like this. You should post your own answer explaining why j is the correct solution.
    – rmaddy
    Nov 17 at 20:49













up vote
1
down vote

favorite









up vote
1
down vote

favorite











When generating date formats from a template with Foundation's DateFormatter for the Locale "de", like this:



let locale: Locale = Locale(identifier: "de")
let format = DateFormatter.dateFormat(fromTemplate: "dMMMyGhhmmss",
options: 0,
locale: locale)


I always get this format:



d. MMM y G, h:mm:ss a


which renders



17. Nov. 2018 n. Chr., 8:30:20 PM


The 'PM' part is unusual for Locale "de", but it is my understanding that this method also takes user preferences into account. Is that correct?



I played around with the settings in System Preferences, e.g. switching to 24-hour clock, but nothing I changed had any effect. Do I have to restart something for the changes to take effect?



Can someone explain to me what's going on?










share|improve this question















When generating date formats from a template with Foundation's DateFormatter for the Locale "de", like this:



let locale: Locale = Locale(identifier: "de")
let format = DateFormatter.dateFormat(fromTemplate: "dMMMyGhhmmss",
options: 0,
locale: locale)


I always get this format:



d. MMM y G, h:mm:ss a


which renders



17. Nov. 2018 n. Chr., 8:30:20 PM


The 'PM' part is unusual for Locale "de", but it is my understanding that this method also takes user preferences into account. Is that correct?



I played around with the settings in System Preferences, e.g. switching to 24-hour clock, but nothing I changed had any effect. Do I have to restart something for the changes to take effect?



Can someone explain to me what's going on?







swift date foundation






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 18 at 4:55

























asked Nov 17 at 19:49









mistercake

372210




372210












  • Change the h to H in your template.
    – rmaddy
    Nov 17 at 20:37










  • @rmaddy Then it also uses the 24-hour format for locale "en". However, your comment prompted me to check the spec again and I found that I could replace h with j, which causes the format generator to pick h or H depending on the locale.
    – mistercake
    Nov 17 at 20:46












  • Good find. I always forget about j. That should be used with a template like this. You should post your own answer explaining why j is the correct solution.
    – rmaddy
    Nov 17 at 20:49


















  • Change the h to H in your template.
    – rmaddy
    Nov 17 at 20:37










  • @rmaddy Then it also uses the 24-hour format for locale "en". However, your comment prompted me to check the spec again and I found that I could replace h with j, which causes the format generator to pick h or H depending on the locale.
    – mistercake
    Nov 17 at 20:46












  • Good find. I always forget about j. That should be used with a template like this. You should post your own answer explaining why j is the correct solution.
    – rmaddy
    Nov 17 at 20:49
















Change the h to H in your template.
– rmaddy
Nov 17 at 20:37




Change the h to H in your template.
– rmaddy
Nov 17 at 20:37












@rmaddy Then it also uses the 24-hour format for locale "en". However, your comment prompted me to check the spec again and I found that I could replace h with j, which causes the format generator to pick h or H depending on the locale.
– mistercake
Nov 17 at 20:46






@rmaddy Then it also uses the 24-hour format for locale "en". However, your comment prompted me to check the spec again and I found that I could replace h with j, which causes the format generator to pick h or H depending on the locale.
– mistercake
Nov 17 at 20:46














Good find. I always forget about j. That should be used with a template like this. You should post your own answer explaining why j is the correct solution.
– rmaddy
Nov 17 at 20:49




Good find. I always forget about j. That should be used with a template like this. You should post your own answer explaining why j is the correct solution.
– rmaddy
Nov 17 at 20:49












1 Answer
1






active

oldest

votes

















up vote
1
down vote













If you use h or H in the template, the format will contain the specified hour format (12-hour or 24-hour), regardless of the locale. Use j instead. This symbol requests the preferred hour format for the locale.



For example, given the template dMMMyGjjmmss, I get:





  • MMM d, y G, h:mm:ss a (12-hour format) for locale "en"


  • d. MMM y G, HH:mm:ss (24-hour format) for locale "de"




Apple's documentation states:




The format string uses the format patterns from the Unicode Technical Standard #35.




The Unicode Technical Standard #35 has this to say about the symbol j:




This is a special-purpose symbol. It must not occur in pattern or skeleton data. Instead, it is reserved for use in skeletons passed to APIs doing flexible date pattern generation. In such a context, it requests the preferred hour format for the locale (h, H, K, or k), as determined by whether h, H, K, or k is used in the standard short time format for the locale. In the implementation of such an API, 'j' must be replaced by h, H, K, or k before beginning a match against availableFormats data. Note that use of 'j' in a skeleton passed to an API is the only way to have a skeleton request a locale's preferred time cycle type (12-hour or 24-hour).







share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53354946%2fpreferred-hour-format-for-locale-in-date-format-template%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote













    If you use h or H in the template, the format will contain the specified hour format (12-hour or 24-hour), regardless of the locale. Use j instead. This symbol requests the preferred hour format for the locale.



    For example, given the template dMMMyGjjmmss, I get:





    • MMM d, y G, h:mm:ss a (12-hour format) for locale "en"


    • d. MMM y G, HH:mm:ss (24-hour format) for locale "de"




    Apple's documentation states:




    The format string uses the format patterns from the Unicode Technical Standard #35.




    The Unicode Technical Standard #35 has this to say about the symbol j:




    This is a special-purpose symbol. It must not occur in pattern or skeleton data. Instead, it is reserved for use in skeletons passed to APIs doing flexible date pattern generation. In such a context, it requests the preferred hour format for the locale (h, H, K, or k), as determined by whether h, H, K, or k is used in the standard short time format for the locale. In the implementation of such an API, 'j' must be replaced by h, H, K, or k before beginning a match against availableFormats data. Note that use of 'j' in a skeleton passed to an API is the only way to have a skeleton request a locale's preferred time cycle type (12-hour or 24-hour).







    share|improve this answer

























      up vote
      1
      down vote













      If you use h or H in the template, the format will contain the specified hour format (12-hour or 24-hour), regardless of the locale. Use j instead. This symbol requests the preferred hour format for the locale.



      For example, given the template dMMMyGjjmmss, I get:





      • MMM d, y G, h:mm:ss a (12-hour format) for locale "en"


      • d. MMM y G, HH:mm:ss (24-hour format) for locale "de"




      Apple's documentation states:




      The format string uses the format patterns from the Unicode Technical Standard #35.




      The Unicode Technical Standard #35 has this to say about the symbol j:




      This is a special-purpose symbol. It must not occur in pattern or skeleton data. Instead, it is reserved for use in skeletons passed to APIs doing flexible date pattern generation. In such a context, it requests the preferred hour format for the locale (h, H, K, or k), as determined by whether h, H, K, or k is used in the standard short time format for the locale. In the implementation of such an API, 'j' must be replaced by h, H, K, or k before beginning a match against availableFormats data. Note that use of 'j' in a skeleton passed to an API is the only way to have a skeleton request a locale's preferred time cycle type (12-hour or 24-hour).







      share|improve this answer























        up vote
        1
        down vote










        up vote
        1
        down vote









        If you use h or H in the template, the format will contain the specified hour format (12-hour or 24-hour), regardless of the locale. Use j instead. This symbol requests the preferred hour format for the locale.



        For example, given the template dMMMyGjjmmss, I get:





        • MMM d, y G, h:mm:ss a (12-hour format) for locale "en"


        • d. MMM y G, HH:mm:ss (24-hour format) for locale "de"




        Apple's documentation states:




        The format string uses the format patterns from the Unicode Technical Standard #35.




        The Unicode Technical Standard #35 has this to say about the symbol j:




        This is a special-purpose symbol. It must not occur in pattern or skeleton data. Instead, it is reserved for use in skeletons passed to APIs doing flexible date pattern generation. In such a context, it requests the preferred hour format for the locale (h, H, K, or k), as determined by whether h, H, K, or k is used in the standard short time format for the locale. In the implementation of such an API, 'j' must be replaced by h, H, K, or k before beginning a match against availableFormats data. Note that use of 'j' in a skeleton passed to an API is the only way to have a skeleton request a locale's preferred time cycle type (12-hour or 24-hour).







        share|improve this answer












        If you use h or H in the template, the format will contain the specified hour format (12-hour or 24-hour), regardless of the locale. Use j instead. This symbol requests the preferred hour format for the locale.



        For example, given the template dMMMyGjjmmss, I get:





        • MMM d, y G, h:mm:ss a (12-hour format) for locale "en"


        • d. MMM y G, HH:mm:ss (24-hour format) for locale "de"




        Apple's documentation states:




        The format string uses the format patterns from the Unicode Technical Standard #35.




        The Unicode Technical Standard #35 has this to say about the symbol j:




        This is a special-purpose symbol. It must not occur in pattern or skeleton data. Instead, it is reserved for use in skeletons passed to APIs doing flexible date pattern generation. In such a context, it requests the preferred hour format for the locale (h, H, K, or k), as determined by whether h, H, K, or k is used in the standard short time format for the locale. In the implementation of such an API, 'j' must be replaced by h, H, K, or k before beginning a match against availableFormats data. Note that use of 'j' in a skeleton passed to an API is the only way to have a skeleton request a locale's preferred time cycle type (12-hour or 24-hour).








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 18 at 4:52









        mistercake

        372210




        372210






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53354946%2fpreferred-hour-format-for-locale-in-date-format-template%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Costa Masnaga

            Fotorealismo

            Sidney Franklin