On Jan 19, 2012, at 2:39 AM, cocoa-dev-requ...@lists.apple.com wrote: > Date: Thu, 19 Jan 2012 13:41:54 +0700 > From: "Gerriet M. Denkmann" <gerr...@mdenkmann.de> > Subject: Printing an NSDate > To: cocoa-dev@lists.apple.com > Message-ID: <cd59692a-8452-4d4b-ad12-e49636f8d...@mdenkmann.de> > Content-Type: text/plain; charset=us-ascii > > I want to print a date on iOS 5.0.1 ignoring the locale. > (this is for logging - not for showing strings to users) > > I assume that NSDate has no sufficient parameters to control the output. > So I tried to use NSDateFormatter. > > The desired output is something like: > NSString *template = @"HH:mm:ss EEE dd. MMM yyyy zzz"; > > NSString *dateFormat = [ NSDateFormatter dateFormatFromTemplate: template > options: 0 locale: nil ]; > NSDateFormatter *dateFormatter = [ [ NSDateFormatter alloc ] init ]; > [ dateFormatter setDateFormat: dateFormat ]; > …
A "template" for [ NSDateFormatter dateFormatFromTemplate: …] is not a format; rather, it is just treated as a list of which fields are desired in a format. The order and formatting of those fields in the template is ignored. The whole point of dateFormatFromTemplate is to take a request for those fields and turn it into an actual locale-appropriate format containing those fields in the locale-appropriate order, with locale-appropriate formatting. If you want to set "HH:mm:ss EEE dd. MMM yyyy zzz" itself as the format, then just pass that directly to [ dateFormatter setDateFormat: … ]. - Peter E _______________________________________________ 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com