• 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: Printing an NSDate
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Printing an NSDate


  • Subject: Re: Printing an NSDate
  • From: Kyle Sluder <email@hidden>
  • Date: Thu, 19 Jan 2012 07:38:42 -0800

On Jan 18, 2012, at 10:41 PM, "Gerriet M. Denkmann" <email@hidden> wrote:

> 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 ];
> NSString *dateString = [ dateFormatter stringFromDate: someDate ];
> [ dateFormatter release ];
>
> 1. problem:
> The date gets output as year, month, day which is NOT what I specified.
>
> 2. problem:
> The output is: date time, NOT time date as requested.
>
> What am I doing wrong?

You used the +dateFormatFromTemplate: method, which is specifically designed and documented to reorder the date components in the current locale. If you don't want this behavior, don't ask for it; use -initWithDateFormat:allowsNaturalLanguage: instead.

You should also call -setLocale: to make sure you get the same symbols and values for all fields. You probably want [NSLocale systemLocale].

--Kyle Sluder_______________________________________________

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

References: 
 >Printing an NSDate (From: "Gerriet M. Denkmann" <email@hidden>)

  • Prev by Date: Re: Printing an NSDate
  • Next by Date: Andreas Grosam <email@hidden>
  • Previous by thread: Re: Printing an NSDate
  • Next by thread: Re: Printing an NSDate
  • Index(es):
    • Date
    • Thread