Objective C / iPhone: How do I extract the actual unicode date format strings for the current region?

别来无恙 提交于 2019-12-11 03:14:25

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/3835882/objective-c-iphone-how-do-i-extract-the-actual-unicode-date-format-strings-fo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!