Getting current time

后端 未结 3 1923
情话喂你
情话喂你 2021-01-25 15:06

I\'m trying to get current hour minutes and seconds. Here is the code I use

NSDate *now = [NSDate date];

NSCalendar *gregorian = [[NSCalendar  alloc]initWithCal         


        
3条回答
  •  春和景丽
    2021-01-25 15:33

    When i run the code it works fine here.

    what's the following line in your code ? Are you sure that it crashes on the third line in the code you pasted ? maybe the code you pasted is not the same than the one in your xcode.

    Edit : it's because you're using %@ in your string which belongs to UTF-8 string. [dateComponents hour] etc. are returning NSInteger, so you should use %d instead.

提交回复
热议问题