How do I get the current date in Cocoa

后端 未结 14 485
醉酒成梦
醉酒成梦 2020-12-04 09:39

I\'m getting started developing for the iPhone and as such I am looking at different tutorials online as well as trying some different things out myself. Currently, I\'m try

14条回答
  •  粉色の甜心
    2020-12-04 10:15

    You need to do something along the lines of the following:

    NSDate *now = [NSDate date];
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSDateComponents *components = [calendar components:NSHourCalendarUnit fromDate:now];
    NSLog(@"%d", [components hour]);
    

    And so on.

提交回复
热议问题