Re: Printing an NSDate
Re: Printing an NSDate
- Subject: Re: Printing an NSDate
- From: Peter Edberg <email@hidden>
- Date: Thu, 19 Jan 2012 09:16:26 -0800
On Jan 19, 2012, at 2:39 AM, email@hidden wrote:
> Date: Thu, 19 Jan 2012 13:41:54 +0700
> From: "Gerriet M. Denkmann" <email@hidden>
> Subject: Printing an NSDate
> To: email@hidden
> Message-ID: <email@hidden>
> 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 (email@hidden)
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:
This email sent to email@hidden