• 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: Ian Spackman <email@hidden>
  • Date: Tue, 18 Feb 2003 09:51:04 +0000

Martedl, febbraio 18, 2003, alle 04:18 , Michael Tsai ha scritto:

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

--

That's much closer than I managed when I tried to get an internationalized time format. But it won't work for the default Austrian, German or Swiss German time formats where the am/pm designator "Uhr" is used for the 24 hour clock but not for the 12 hour clock.

Cheers,
Ian

email@hidden
_______________________________________________
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.

  • Follow-Ups:
    • Re: formatting NSDate
      • From: Andreas Mayer <email@hidden>
  • Prev by Date: image mask
  • Next by Date: Re: NSTableView doesn't work right all the time...
  • Previous by thread: Re: formatting NSDate
  • Next by thread: Re: formatting NSDate
  • Index(es):
    • Date
    • Thread