Created
December 3, 2013 12:50
-
-
Save sag333ar/7768648 to your computer and use it in GitHub Desktop.
* 'just now'
* '2 minutes ago'
* '24 days ago'
* 'a month ago' Manipulate date & get data in string format as above.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ (NSString *)stringForTimeIntervalSinceCreated:(NSDate *)dateTime serverTime:(NSDate *)serverDateTime{ | |
NSInteger MinInterval; | |
NSInteger HourInterval; | |
NSInteger DayInterval; | |
NSInteger DayModules; | |
NSInteger interval = abs((NSInteger)[dateTime timeIntervalSinceDate:serverDateTime]); | |
if(interval >= 86400) { | |
DayInterval = interval/86400; | |
DayModules = interval%86400; | |
if(DayModules!=0) { | |
if(DayModules>=3600){ | |
//HourInterval=DayModules/3600; | |
return [NSString stringWithFormat:@"%i days", DayInterval]; | |
} else { | |
if(DayModules>=60){ | |
//MinInterval=DayModules/60; | |
return [NSString stringWithFormat:@"%i days", DayInterval]; | |
} else { | |
return [NSString stringWithFormat:@"%i days", DayInterval]; | |
} | |
} | |
} else { | |
return [NSString stringWithFormat:@"%i days", DayInterval]; | |
} | |
} else { | |
if(interval>=3600) { | |
HourInterval= interval/3600; | |
return [NSString stringWithFormat:@"%i hours", HourInterval]; | |
} else if(interval>=60){ | |
MinInterval = interval/60; | |
return [NSString stringWithFormat:@"%i minutes", MinInterval]; | |
} else { | |
return [NSString stringWithFormat:@"%i Sec", interval]; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment