Tuesday, 14 October 2014

Distance between two time.

Here we  goooooo..........


-(void)tempo
{
   // NSDate *earlier = [[NSDate alloc]initWithTimeIntervalSinceReferenceDate:1];
    NSDate *today = [NSDate date];
    
    NSCalendar *gregorian = [[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar];
    
    // pass as many or as little units as you like here, separated by pipes
    NSUInteger units = NSYearCalendarUnit | NSDayCalendarUnit | NSMonthCalendarUnit |NSHourCalendarUnit |NSMinuteCalendarUnit|NSSecondCalendarUnit;
    
    NSDateComponents *components = [gregorian components:units fromDate:date1 toDate:today options:0];
    
    NSInteger years = [components year];
    NSInteger months = [components month];
    NSInteger days = [components day];
    NSInteger h = [components hour];
    NSInteger m = [components minute];
    NSInteger s = [components second];
    
    
    NSLog(@"Years: %ld, Months: %ld, Days: %ld hour: %ld mint: %d sec: %ld", (long)years, (long)months, (long)days,(long)h,m,(long)s);
    days=days*86400;
    h=h*3600;
    m=m*60;
    int total=days+m+h+s;
    NSLog(@"total:=%d",total);
    
    NSLog(@"Years: %ld, Months: %ld, Days: %ld hour: %ld mint: %d sec: %ld", (long)years, (long)months, (long)days,(long)h,m,(long)s);
    
    
    int dayIs=total/86400;
    int hours=total%86400;
    hours=hours/24;
    int minti=hours%24;
    minti=minti/3600;
    int sec=minti%3600;
    sec=sec/60;
    
        
    
    

}

No comments:

Post a Comment