2011-10-19 118 views
0

哈二,我知道如何在甲酸鹽iPhone上的日期,但我必須設定日期的圖像below.My代碼給出的 imageNSDateFormator在iphone懷疑

NSDate* date = [NSDate date]; 

    //Create the dateformatter object 

    NSDateFormatter* formatter = [[[NSDateFormatter alloc] init] autorelease]; 

    //Set the required date format 

    [formatter setDateFormat:@"yyyy:mm:dd"]; 

    //Get the string date 

    NSString* str = [formatter stringFromDate:date]; 

    //Display on the console 

    // NSLog(str); 

    //Set in the lable 

    [_lbldateLabel setText:str]; 

如何修改我的上面的代碼來獲取圖像給出的當前日期? 在此先感謝。

回答

1
try this 
NSDateFormatter* formatter = [[[NSDateFormatter alloc] init] autorelease]; 

    //Set the required date format 

    [formatter setDateFormat:@"MMM dd/yy"]; 

    //Get the string date 

    NSString* str = [formatter stringFromDate:date]; 
+0

它工作的很好,但我想顯示年份的上半部分,然後在年份的下一個日期和月份,如上面提到的圖片.thankz。 – ICoder

+0

爲此,您可以通過單獨的字符串來管理它並將其顯示出來 – Ron

+0

如果您想對組件重新排序,它不應該是那麼神祕。如果你想要一個只有月份的字符串,將格式設置爲@「MMM」。調用stringFromDate:然後將格式更改爲另一個組件並以相同的方式獲取該字符串。 – NJones