• 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: Wed, 19 Feb 2003 17:39:33 +0000

[The next line was generated by Mail.app, with language prefs as British English and date, and time prefs as German]

On Mittwoch, Februar 19, 2003, at 12:10 Uhr, Andreas Mayer wrote:

Am Dienstag, 18.02.03 um 10:51 Uhr schrieb Ian Spackman:

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.

There is no official 12 hour time format in Germany AFAIK. So this setting is meaningless; do with it whatever you like. ;)

(Of course we say "sechs Uhr abends" (6 o'clock in the evening), but we do not have a written form of this; it's always written as "18 Uhr" or "18:00".)


bye. Andreas.


I stand happily corrected, Andreas. ;)

What you say implies that Apple's default values for System Preferences > International > Time > Region = German are bad. At least under 10.1. Maybe they have been improved under 10.2.

It is interesting, though, that both Mail.app and the menu bar clock (currently "Mit 17:31 Uhr" for the 24-hour clock and "Mit 17:31" for the 12-hour clock) _are_ picking up the use of the am/pm designator with the 24-hour clock. I had assumed that attempting to follow Apple's apps in this respect was the thing to do.

Anyway if - despite Andreas' cautions - anyone does still want the 'menu bar clock' style of localized time string, the following does seem to work as a category on NSCalendarDate. Caution, though: if I am a beginner at Cocoa I am a total neophyte at Carbon and felt peculiarly clueless while poking around the Apple site trying to work out how to do this! I would therefore very much appreciate criticisms of the code.


@implementation NSCalendarDate (BILocalAdditions)

-(NSString *) localizedTimeStringWithSeconds:(BOOL)includeSeconds
{
Str255 result;
int sLen;
//midnight, January 1, 1904 (I assume it's the beginning of the day that's needed, not the end of the day)
NSCalendarDate *date1904 = [NSCalendarDate dateWithYear:1904 month:0 day:1 hour:0 minute:0 second:0 timeZone:nil];

LongDateTime dateTime1904 = (LongDateTime)[self timeIntervalSinceDate:date1904];
LongTimeString( &dateTime1904, (Boolean)includeSeconds, result, NULL); //NULL to pick up the current localization

// This is ugly: no doubt there are better ways to get a C string from a Pascal style Str255
// And anyway how do I know what encoding the Str255 is using?
sLen = result[0];
memmove(result, result+1, sLen);
result[sLen]=0; // should now have a C string in result

return [NSString stringWithCString:result];
}
@end




(BTW, I probably should have explained in my earlier message that I was writing not on the basis of my distant attempts to learn German at school - my linguistic talents are shameful even by English standards - but rather by looking at what my Mac did when I changed the preferences to various regions.)

Best wishes,
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>
References: 
 >Re: formatting NSDate (From: Andreas Mayer <email@hidden>)

  • Prev by Date: Re: Weirdness on window redraw
  • Next by Date: Can't cache image ?
  • Previous by thread: Re: formatting NSDate
  • Next by thread: Re: formatting NSDate
  • Index(es):
    • Date
    • Thread