Re: formatting NSDate
Re: formatting NSDate
- Subject: Re: formatting NSDate
- From: Michael Tsai <email@hidden>
- Date: Mon, 17 Feb 2003 23:18:33 -0500
On Monday, February 17, 2003, at 08:54 PM, Jonathan Jackel wrote:
>
> Is it possible format dates in the user's preffered Short Date
>
> format as set in the International preference panel? I can't seem
>
> to find it in NSDate or NSDateFormatter.
>
[[NSUserDefaults standardUserDefaults] NSShortTimeDateFormatString]
Unfortunately, NSShortTimeDateFormatString does not follow the settings
in the International preference pane. NSTimeFormatString and
NSShortDateFormatString do, except that NSTimeFormatString doesn't add
the AM/PM designation when necessary.
Here's the code I'm using to print time-date strings:
@implementation NSDate (MJT)
- (NSString *)mjtShortTimeDateString
{
NSString *format = [NSString stringWithFormat:@"%@ %@",
[defaults stringForKey:NSShortDateFormatString],
[defaults stringForKey:NSTimeFormatString]];
// ensure AM/PM if 12-hour
if ( [format mjtContainsString:@"I"] &&
![format mjtContainsString:@"%p"] )
format = [format stringByAppendingString:@"%p"];
// doesn't localize if you pass nil
NSDictionary *locale = [defaults dictionaryRepresentation];
return [self descriptionWithCalendarFormat:format
timeZone:nil
locale:locale];
}
@end
--
Michael Tsai <
http://www.c-command.com>
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.