麻烦在UILabel上显示日期?

时间:2013-02-26 04:32:52

标签: uilabel nsdate nsdateformatter

我正在尝试获取标签,以(月)XX,XXXX格式显示日期

使用:

    currentDate = [NSDate date];
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setTimeStyle:NSDateFormatterShortStyle];
    date.text = [dateFormat stringFromDate:currentDate];

不幸的是,标签文本甚至没有改变,我做错了什么?

1 个答案:

答案 0 :(得分:1)

试试这个

  first you have set IBOutlet connection date label

NSDate *currentDate = [NSDate date];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"MM  YYYY"];
date.text = [dateFormat stringFromDate:currentDate]