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?
swift date foundation
add a comment |
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?
swift date foundation
Change theh
toH
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 replaceh
withj
, which causes the format generator to pickh
orH
depending on the locale.
– mistercake
Nov 17 at 20:46
Good find. I always forget aboutj
. That should be used with a template like this. You should post your own answer explaining whyj
is the correct solution.
– rmaddy
Nov 17 at 20:49
add a comment |
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?
swift date foundation
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
swift date foundation
edited Nov 18 at 4:55
asked Nov 17 at 19:49
mistercake
372210
372210
Change theh
toH
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 replaceh
withj
, which causes the format generator to pickh
orH
depending on the locale.
– mistercake
Nov 17 at 20:46
Good find. I always forget aboutj
. That should be used with a template like this. You should post your own answer explaining whyj
is the correct solution.
– rmaddy
Nov 17 at 20:49
add a comment |
Change theh
toH
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 replaceh
withj
, which causes the format generator to pickh
orH
depending on the locale.
– mistercake
Nov 17 at 20:46
Good find. I always forget aboutj
. That should be used with a template like this. You should post your own answer explaining whyj
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
add a comment |
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).
add a comment |
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).
add a comment |
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).
add a comment |
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).
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).
answered Nov 18 at 4:52
mistercake
372210
372210
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Change the
h
toH
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
withj
, which causes the format generator to pickh
orH
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 whyj
is the correct solution.– rmaddy
Nov 17 at 20:49