• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: formatting NSDate
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Prev by Date: Who should have control?
  • Next by Date: Re: Restricting an NSSplitView when Resizing a Window
  • Previous by thread: Re: formatting NSDate
  • Next by thread: Re: formatting NSDate
  • Index(es):
    • Date
    • Thread