开发者

error getting time from phone in xcode 4?

开发者 https://www.devze.com 2023-03-16 22:12 出处:网络
I trying to fetch the time from the phone\'s clock but am not able to fetch using this code NSDate *today = [NSDate date];

I trying to fetch the time from the phone's clock but am not able to fetch using this code

NSDate *today = [NSDate date];
    NSCalendar *gregorian = [[NSCalendar alloc]
                             initWithCalendarIdentifier:NSGregorianCalendar];

NSInteger hour = [components hour];
    NSInteger minute = [components minute];
    NS开发者_运维问答Integer second = [components second];


Use This

NSDate *today = [NSDate date];
    NSCalendar *gregorian = [[NSCalendar alloc]
                             initWithCalendarIdentifier:NSGregorianCalendar];
    NSDateComponents *components =
    [gregorian components:(NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit) fromDate:today];

    NSInteger hour = [components hour];
    NSInteger minute = [components minute];
    NSInteger second = [components second];

You missed a line in the code.

0

精彩评论

暂无评论...
验证码 换一张
取 消