tags:

views:

109

answers:

1

hi, i am getting second from NSDateComponents.but it returns long number,how can i get correct second..?for example 55 sec...(it is as 123232133 like that)

     NSCalendar *sCalendar = [NSCalendar currentCalendar];


    unsigned int unitFlags = NSHourCalendarUnit | NSMinuteCalendarUnit |     
   NSDayCalendarUnit | NSMonthCalendarUnit;

 NSDateComponents *Info = [sCalendar components:unitFlags 
  fromDate:date1  toDate:date2  options:0];

   NSLog(@" %dsec ",[Info second]);

it prints like 2323324324....

+1  A: 

You need to add NSSecondCalendarUnit to your flags when creating the components to get it to include seconds in the result.

Rhult
i added ,,,same result..?
Mikhail Naimy
For iphone you might need to cast the result to an int when logging with "%d" since NSInteger is a long integer on iphone and %d expects an int (or use "%ld").
Rhult