> > > >I'm getting stuck trying to format a variable quantity of elapsed time >for the user's locale. The NSDateFormatter class seems to only provide >formats for actual times (e.g. "1:30 AM"). What I need to do is turn 1 >hour and 30 minutes into "1:30" for my US English settings, and the >appropriate string for other locales.
Hi Dennis If you want to have full control of the output of an NSDateFormatter object and you do not have to support anything earlier than Snow Leopard, I strongly recommend that you use -[NSDateFormatter dateFormatFromTemplate:options:locale:]. See the documentation of this method and check the link to the Unicode Technical Standard #35. You can then ask for the exact time components you need to print out. However, if you need to target earlier OS'es that's doable also but you need more work to accomplish the same thing, something like: NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateStyle:NSDateFormatterNoStyle]; // prevents the date from being printed out [formatter setTimeStyle:NSDateFormatterShortStyle]; // it will include the AM/PM However, you can look for occurrences of the AM/PM strings of a given locale by sending -[NSDateFormatter AMSymbol] and -[NSDateFormatter PMSymbol] and then deleted them from the time string with the appropriate NSString methods. [formatter release]; // shouldn't forget to release it when you're done HTH João _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com