2010-08-02 176 views

回答

-1

或者你可以只使用的NSDate類:

NSDate *date = [NSDate date]; 
    int month = [[date descriptionWithCalendarFormat:@"%m" timeZone:nil locale:nil] intValue]; 
    int day = [[date descriptionWithCalendarFormat:@"%d" timeZone:nil locale:nil] intValue]; 
    int year = [[date descriptionWithCalendarFormat:@"%Y" timeZone:nil locale:nil] intValue]; 

    NSLog(@"Today: %i-%i-%i", year, month, day); 

希望工程, ief2

+0

這就是我一直在尋找的! – Slee 2010-08-02 21:49:34

+0

它是公開的API嗎?我得到了這個警告。 – karim 2011-04-14 09:53:40

+0

它現在可能已被棄用 – v1Axvw 2011-04-14 20:26:56

2

你要這個NSDateCOmponenets

明確:

- (NSDateComponents *)components:(NSUInteger)unitFlags fromDate:(NSDate *)date 
+0

譜曲從未定義這裏?我只是想把當前的日期分成幾部分,對於這樣一個簡單的東西看起來很複雜 – Slee 2010-08-02 18:21:53

+1

welcome to objective-c! – ennuikiller 2010-08-02 18:29:07