Objective C / iPhone:如何提取当前区域的实际 unicode 日期格式字符串?

发布于 2024-09-25 23:53:07 字数 509 浏览 1 评论 0原文

根据该网站: http://iosdevelopertips.com/cocoa/date-formatter-examples.html

有一个处理格式化的类,它接受一组常量/枚举(例如 NSDateFormatterShortStyle)到“setDateStyle”属性/方法。

NSDateFormatter 知道以某种方式检索正确的特定于区域设置的日期格式。我想要的是能够根据用户选择的区域格式检索默认格式。我有一种感觉它存储在 NSLocale 中,但这似乎没有公开任何可以检索格式字符串的内容。

有没有办法提取格式?它必须在内存中的某个地方;我希望检索机制暴露在某个地方。

我已经查看了几个地方,但我得到的唯一答案是关于如何从自定义格式创建 NSDate 的课程。

According to this site:
http://iosdevelopertips.com/cocoa/date-formatter-examples.html

there is a class that handles formatting, which takes in a set of constants/enums (e.g. NSDateFormatterShortStyle) to the "setDateStyle" property/method.

Somehow the NSDateFormatter knows to retrieve the proper locale-specific date format. What I want is to be able to retrieve the default formats based on the user's choice of region format. I have a feeling it is stored in NSLocale, but that does not seem to expose anything that will retrieve the format strings.

Is there a way to extract the formats? It has to be in memory somewhere; I'm hoping the retrieval mechanism is exposed somewhere.

I've looked in several places, but the only answers I get are a lesson on how to create an NSDate from a custom format.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

初见你 2024-10-02 23:53:07
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateStyle:NSDateFormatterShortStyle];
NSString *dateFormat = [df dateFormat];
NSLog(@"Date format: %@", dateFormat);
[df release];

刚刚在 OS X 上进行了测试,但这应该也适用于 iOS。

NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateStyle:NSDateFormatterShortStyle];
NSString *dateFormat = [df dateFormat];
NSLog(@"Date format: %@", dateFormat);
[df release];

Just tested on OS X but this should also work in iOS.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文