目标C / iPhone:如何提取当前区域的实际unicode日期格式字符串? [英] Objective C / iPhone: How do I extract the actual unicode date format strings for the current region?
问题描述
我是全新的客观c和iphone开发,所以请温柔(刚开始看代码今晚第一次)。
I am completely new to objective c and iphone development, so please be gentle (just started looking at the code for the first time tonight).
根据这个网站:
http://iphonedevelopertips.com/cocoa/date-formatter-examples .html
有一个类处理格式化,它将一组常量/枚举(例如NSDateFormatterShortStyle)传递给setDateStyle属性/方法
there is a class that handles formatting, which takes in a set of constants/enums (e.g. NSDateFormatterShortStyle) to the "setDateStyle" property/method.
NSDateFormatter知道要检索适当的区域设置特定的日期格式。我想要的是能够根据用户对区域格式的选择来检索默认格式。我有一种感觉存储在NSLocale中,但似乎没有任何可以检索格式字符串的东西。
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.
我在几个地方看过(iphone dev指南,stackoverflow和random iphone帮助网站),但我得到的唯一答案是如何从自定义格式创建NSDate的一个教训。
I've looked in several places (iphone dev guide, stackoverflow, and random iphone help sites), but the only answers I get are a lesson on how to create an NSDate from a custom format.
提前感谢。
推荐答案
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateStyle:NSDateFormatterShortStyle];
NSString *dateFormat = [df dateFormat];
NSLog(@"Date format: %@", dateFormat);
[df release];
只是在OS X上测试,但这也应该在iOS中运行。
Just tested on OS X but this should also work in iOS.
这篇关于目标C / iPhone:如何提取当前区域的实际unicode日期格式字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!