Date formatters examples in Objective-C 
Date formatters examples in Objective-C

Here are several simple examples for displaying date information:

// Date: 10/29/08

NSDate *today = [NSDate dateWithTimeIntervalSinceNow:0];
NSDateFormatter *dateFormat = [[[NSDateFormatter alloc] init] autorelease];
[dateFormat setDateStyle:NSDateFormatterShortStyle];
NSString *dateString = [dateFormat stringFromDate:today];
NSLog(@"Date: %@", dateString);

// Date: 10/29/2008 08:29PM

NSDate *today = [NSDate date];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"MM/dd/yyyy hh:mma"];
NSString *dateString = [dateFormat stringFromDate:today];
NSLog(@"Date: %@", dateString);
[dateFormat release];


No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

You must be logged in to post a comment.

---