在xcode标签中创建日期

shy*_*shy 2 xcode label date objective-c swift

首先要提前感谢帮助我...

我想知道如何使用xcode在标签中创建日期.和日期将在iphone之后的同一天...

谢谢

我仍然很新,有很多东西需要学习..

joh*_*les 5

这是一个简单的方法

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
Run Code Online (Sandbox Code Playgroud)