shy shy - 11 months ago 61
Objective-C Question

create a date in xcode label

HI all,

first of all want to say thanks in advance for helping me...

i want to know how can i create a date in label using xcode.
and the date will follow the same date like in iphone...


im still new and got lots to learn..


Here's one simple approach

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
//uncomment to get the time only
//[formatter setDateFormat:@"hh:mm a"];
//[formatter setDateFormat:@"MMM dd, YYYY"];
[formatter setDateStyle:NSDateFormatterMediumStyle];

//get the date today
NSString *dateToday = [formatter stringFromDate:[NSDate date]];

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320.0f, 20.0f)];
[label setText:dateToday];
[formatter release];

//then add to a view