ios - Issue in finding time difference -


in app, want know difference between:

the total hours worked in week(54.30 hours)

and

the total hours worked on specific day(10.45 hours)

for example, want know value of (54.30 hours - 10.45 hours) in hours. since total hours of week greater 24 hrs, couldn't convert nsdate.

use 2 functions,this you

the below function return total seconds hour string

- (nsnumber *)secondsfortimestring:(nsstring *)string {     nsarray *components = [string componentsseparatedbystring:@"."];     nsinteger hours   = [[components objectatindex:0] integervalue];     nsinteger minutes = [[components objectatindex:1] integervalue];     //nsinteger seconds = [[components objectatindex:2] integervalue];    return [nsnumber numberwithinteger:(hours * 60 * 60) + (minutes * 60)]; 

}

and below function return formatted time seconds

- (nsstring *)timeformatted:(int)totalseconds {     //int seconds = totalseconds % 60;     int minutes = (totalseconds / 60) % 60;     int hours = totalseconds / 3600;     return [nsstring stringwithformat:@"%02d.%02d",hours, minutes]; } 

now can calculate remaining hours :

int diffrence =[[self secondsfortimestring:@"54.30"] intvalue] - [[self secondsfortimestring:@"10.45"] intvalue]; nslog(@"remaining hours - %@",[self timeformatted:diffrence]); 

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -