• 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: Andreas Grosam <email@hidden>
  • Date: Thu, 19 Jan 2012 11:36:14 +0100

On Jan 19, 2012, at 7:41 AM, Gerriet M. Denkmann wrote:

> 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 ];
> 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?
>
> Kind regards,
>
> Gerriet.


Maybe this is what you are looking for:

NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat: @"HH:mm:ss EEE dd. MMM yyyy zzz"];
NSString* dateString = [dateFormatter stringFromDate: [NSDate date]];
[dateFormatter release];

NSLog(@"\n%@", dateString);

prints:
11:31:42 Thu 19. Jan 2012 GMT+01:00



The documentation could be a bit more clear in this regard, but please re-read it ;)


Andreas_______________________________________________

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: Get OS version of iOS device connected to Mac OS X
  • Next by Date: Re: Printing an NSDate
  • Previous by thread: Printing an NSDate
  • Next by thread: Re: Printing an NSDate
  • Index(es):
    • Date
    • Thread