Get NSDate to say "XX time ago" that article was published [duplicate] - ios

This question already has answers here:
Is there some functionality in Cocoa to display time intervals in natural language?
(4 answers)
Closed 9 years ago.
I have a date an article was published, but need to get how long ago it was published in relation to the current time.
So if the Article was published at 8:45AM, and it is 9:45AM on the same day, I need to be able to have a UILabel that says "1 hr ago".
Currently, I am getting the date formatted to get a date like "May 5, 2013 5:35PM":
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
Feed *feedLocal = [headlinesArray objectAtIndex:indexPath.row];
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:#"MMMM d, yyyy h:mma"];
NSString *dateString = [df stringFromDate:feedLocal.published];
cell.publishedLabel.text = dateString;
}
How could I convert that to get something like "1 hr ago"? Thanks!
EDIT
Here is the current method I have to at least get the time ago:
-(NSString *)timeAgo {
NSDate *todayDate = [NSDate date];
double ti = [self timeIntervalSinceDate:todayDate];
ti = ti * -1;
if (ti < 1) {
return #"1s";
} else if (ti < 60) {
return #"1m";
} else if (ti < 3600) {
int diff = round(ti / 60);
return [NSString stringWithFormat:#"%dm", diff];
} else if (ti < 86400) {
int diff = round(ti / 60 / 60);
return[NSString stringWithFormat:#"%dh", diff];
} else if (ti < 2629743) {
int diff = round(ti / 60 / 60 / 24);
return[NSString stringWithFormat:#"%dd", diff];
} else if (ti < 31556926) {
int diff = round(ti / 60 / 60 / 24 / 30);
return [NSString stringWithFormat:#"%dmo", diff];
} else {
int diff = round(ti / 60 / 60 / 24 / 30 / 12);
return [NSString stringWithFormat:#"%dy", diff];
}
}

Im not sure what timeAgo is a method of, but here is a solution assuming its in the same viewController as tableView:cellForRowAtIndexPath. If you can clarify what its a method of I may be able to modify this and help you more.
First change timeAgo to take in a date and do a comparison on it.
-(NSString *)timeSincePublished:(NSDate *)publicationDate
{
double ti = [publicationDate timeIntervalSinceNow];
Everything else should be the same in the above method.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
Feed *feedLocal = [headlinesArray objectAtIndex:indexPath.row];
NSString *dateString = [self timeSincePublished:feedLocal.published];
cell.publishedLabel.text = dateString;
}

Related

Convert String to Float to move UISlider

How I can convert time of my JSON data to float value. Below code is written to convert time to float and I passed it to UISlider as total length of audio. I want to move slider with that time spans
//Json Data
{
duration = "00:03:45";
id = 8;
}
//Audio player sider bar function
if(audioController.playbackState == MPMusicPlaybackStatePlaying){
if (isSelected == YES) {
currentAutio = audioList[selectedAudio];
} else {
currentAutio = audioList[0];
}
NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
numberFormatter.numberStyle = NSNumberFormatterDecimalStyle;
float value = [numberFormatter numberFromString:currentAutio.duration].floatValue;
float currentPlaybackTime = [audioController currentPlaybackTime];
float TotalLength = value;
float remainingPlaybackTime = TotalLength - currentPlaybackTime;
float sliderPosition = (currentPlaybackTime *100) / TotalLength;
NSLog(#"current playbacktime %f",currentPlaybackTime);
NSLog(#"TotalLength %f",TotalLength);
NSLog(#"remainingPlaybackTime %f",remainingPlaybackTime);
NSLog(#"sliderPosition %f",sliderPosition);
//Update slider
[progressSlider setValue:sliderPosition];
//Update labels
NSDate* d1 = [NSDate dateWithTimeIntervalSince1970:currentPlaybackTime];
NSDate* d2 = [NSDate dateWithTimeIntervalSince1970:remainingPlaybackTime];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:#"mm:ss"];
NSString *currentTime = [dateFormatter stringFromDate:d1];
NSString *ramainingTime = [dateFormatter stringFromDate:d2];
[trackCurrentPlaybackTimeLabel setText:currentTime];
[trackLengthLabel setText:[NSString stringWithFormat:#"-%#",ramainingTime]];
}
I am getting following output:
Value = 0.00000
I don't think there is a built-in mechanism for converting a time interval into a float, but it's trivially easy to write:
func timeIntervalFrom(_ timeString: String) -> TimeInterval? {
//Add code to validate that string is in correct format
let components = time.components(separatedBy: ":")
guard components.count == 3,
let hours = Double(components[0]),
let minutes = Double(components[1]),
let seconds = Double(components[2]) else {
return nil
}
return hours * 3600 + minutes * 60 + seconds
}
Just convert the duration from String to integer components.
Then calculate the total duration in seconds.
You can get the integer components simply like this:
Swift
let timeComponents = duration.components(separatedBy: ":")
Objective C
NSArray *timeComponents = [duration componentsSeparatedByString:#":"];
timeComponents[0] will be the hours part.
timeComponents[1] will be the minutes part.
timeComponents[2] will be the seconds part.
Total seconds: (hours * 60 * 60) + (minutes * 60) + seconds.
After that, adjusting the slide bar value will be easy :)

running timers in tableViewCells being overwritten when tableView scrolls

I have tried asking this question several times but I haven't been able to explain what is going on. Maybe some screen shots may help. I can only post one because I don't have enough reputation points yet.
screenshot after tableview scroll
You can see that one of the timers (2) has been reset. I have tried to fix this multiple ways without success. Here is the code that puts the timers into the tableview cells:
-(void) calculateTimer:(NSTimer *)theTimer
{
self.timerItem = [theTimer userInfo];
// for date only cell
if(self.timerItem.timerType == 0){
[theTimer invalidate];
}
for (NRCItemCell *cell in [self.tableView visibleCells])
{
NSIndexPath *ip = [self.tableView indexPathForCell:cell];
NSUInteger row = [[[NRCItemStore sharedStore]allItems] indexOfObjectIdenticalTo:self.timerItem];
if (row == ip.row){
[self configureTimers:cell forRowAtIndexPath:ip];
cell.timer.text = self.timerItem.timerOutput;
cell.timerName.text = self.timerItem.timerName;
}
}
}
-(void)configureTimers:(NRCItemCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
NRCtimerItem *item = [[NRCItemStore sharedStore]allItems][indexPath.row];
NSInteger timerType = item.timerType;
// timerType set by TimerTypeTableView Controller as follows:
// 0 - date
// 1 - seconds elapsed
// 2 - minutes elapsed
// 3 - hours elapsed
// 4 - days elapsed
// 5 - months elapsed
// 6 - years elapsed
switch (timerType) {
case 0:{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
[dateFormatter setTimeStyle:NSDateFormatterNoStyle];
NSDate *date = [NSDate date];
NSString *formattedDateString = [dateFormatter stringFromDate:date];
item.timerOutput = formattedDateString;
}
break;
case 1:
{
NSTimeInterval interval = [self.timerItem.startTime timeIntervalSinceNow];
interval = (-1 * interval);
int time = round(interval);
div_t h = div(time, 3600); //seconds total, divided by 3600 equals
int hours = h.quot; // hours, divided by 60 equals
div_t m = div(h.rem, 60); // minutes
int minutes = m.quot;
int seconds = m.rem; // and remainder is seconds
// NSLog(#"%d:%d:%d", hours, minutes, seconds);
//NSString *intervalString = [NSString stringWithFormat:#"%ld", (long)time];
NSString *intervalString = [NSString stringWithFormat:#"%d hours, %d minutes, %d seconds", hours, minutes, seconds];
NSString *outputString = [intervalString stringByAppendingString:#" ago"];
item.timerOutput = outputString;
}
break;
case 2:
{
NSTimeInterval interval = [self.timerItem.startTime timeIntervalSinceNow];
interval = (-1 * interval);
int time = roundf(interval);
div_t h = div(time, 3600); // seconds total, divided by 3600 equals
int hours = h.quot; // hours, divided by 60 equals
div_t m = div(h.rem, 60); // minutes
int minutes = m.quot;
NSString *intervalString = [NSString stringWithFormat:#"%d hours, %d minutes", hours, minutes];
NSString *outputString = [intervalString stringByAppendingString:#" ago"];
item.timerOutput = outputString;
}
break;
case 3:
{
NSTimeInterval interval = [self.timerItem.startTime timeIntervalSinceNow];
interval = (-1 * interval);
int time = roundf(interval);
div_t h = div(time, 3600); // seconds total, divided by 3600 equals
int hours = h.quot; // hours
NSString *intervalString = [NSString stringWithFormat:#"%d hours", hours];
NSString *outputString = [intervalString stringByAppendingString:#" ago"];
item.timerOutput = outputString;
}
break;
case 4:
{
NSTimeInterval interval = [self.timerItem.startTime timeIntervalSinceNow];
interval = (-1 * interval);
int time = roundf(interval);
div_t h = div(time, 3600); // seconds total, divided by 3600 equals
int hours = h.quot; // hours, divided by 24 equals
div_t d =div(h.rem, 24); // days
int days = d.quot;
NSString *intervalString = [NSString stringWithFormat:#"%d days, %d hours", days, hours];
NSString *outputString = [intervalString stringByAppendingString:#" ago"];
item.timerOutput = outputString;
}
break;
case 5:
{
NSTimeInterval interval = [self.timerItem.startTime timeIntervalSinceNow];
interval = (-1 * interval);
int time = roundf(interval);
div_t h = div(time, 3600); // seconds total, divided by 3600 equals
__unused int hours = h.quot; // hours, divided by 24 equals
div_t d =div(h.rem, 24); // days
int days = d.quot;
div_t y = div(d.rem, 12);// divided by 12 equals months
int months = y.quot;
NSString *intervalString = [NSString stringWithFormat:#"%d months, %d days", months, days];
NSString *outputString = [intervalString stringByAppendingString:#" ago"];
item.timerOutput = outputString;
}
break;
case 6:
{
NSTimeInterval interval = [self.timerItem.startTime timeIntervalSinceNow];
interval = (-1 * interval);
int time = roundf(interval);
div_t h = div(time, 3600); // seconds total, divided by 3600 equals
__unused int hours = h.quot; // hours, divided by 24 equals
div_t d =div(h.rem, 24); // days
int days = d.quot;
div_t y = div(d.rem, 365);// divided by 365 equals years
int years = y.quot;
NSString *intervalString = [NSString stringWithFormat:#"%d years, %d days", years, days];
NSString *outputString = [intervalString stringByAppendingString:#" ago"];
item.timerOutput = outputString;
}
break;
}
}
The key is the for(NRCItemCell *cell in [self.tableView visibleCells]) fast enumeration. The idea is to loop through the visible cells and only update a cell if the cell's indexPath is equal to the position of the timer in my datastore. However, it looks like scrolling the tableView causes a mismatch between indexPath and and position of the timer in the datastore so that the wrong cell gets overwritten. I have searched all over for an answer and have tried several different approaches but the solution depends on the subtitle label in my custom cell not being overwritten unless the cell position matches the datastore position (which is the way MVC should work, as I understand it). But using reusable cells and scrolling apparently doesn't work the way I thought it did. If there is a solution, I sure would like the help. Thanks in advance!
Your main issue here is the reuse of the cells. Every time you scroll the table the cells are reused with the data of other cells. To keep it short, store your timers data in an array and not in the actual cell.
Importent pointers:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
...
cell.timerView.data = nil; //reset the data in the current timer
myCell *updateCell = (id)[tableView cellForRowAtIndexPath:indexPath];
if (updateCell)// Makes sure the cell is still visible
updateCell.timerView.data = timersArray[indexpath.row];
});
}
My bad. I found the bug in my code. It wasn't with tableView at all. I was storing the timers in an array, correctly, not in the cell, even though that's what the comments in the code said. The bug was that I was inadvertently firing a timer every pass through the tableView, so these timers would fire at unpredictable times and then my code would overlay the cell for the corresponding timer. A lot of debugging work, but good experience. Code is working now.
Thanks for the comments!

Is it possible align text to both the left and right in a section heading in a tableview?

I am trying to have some text aligned to the left of the section heading and different text to the right of the same heading.
While using toolBars I have used a flexible button to push both other buttons to the left and right and I was wondering if there was a similar thing for section headings?
A little bit more background is that I have a different section in my tableview for every piece of information entered on each different day. On the left of the section heading I want the date it was entered (Wed 20th Nov) and on the right I want how many days ago that was (20 days ago).
Here is the code I am currently using:
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
if (section == 0) {
return nil;
}
else {
// This gets the day the data was entered
NSDate * date = [_sectionDates objectAtIndex:(section-1)];
NSDateFormatter * formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:#"EEE"];
NSString * dateDay = [formatter stringFromDate:date];
[formatter setDateFormat:#"MMM"];
NSString * dateMonth = [formatter stringFromDate:date];
NSDateComponents * components = [[NSCalendar currentCalendar] components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear fromDate:date];
NSInteger dateOfDay = [components day];
NSTimeInterval diff = [[NSDate date] timeIntervalSinceDate:date];
NSInteger days = diff / (60.0 * 60.0 * 24);
NSString * dateScript;
if (dateOfDay < 21 && dateOfDay > 4) {
dateScript = #"th";
}
else if (dateOfDay % 10 == 1) {
dateScript = #"st";
}
else if (dateOfDay % 10 == 2) {
dateScript = #"nd";
}
else if (dateOfDay % 10 == 3) {
dateScript = #"rd";
}
else {
dateScript = #"th";
}
NSString * header;
if (days < 2) {
header = [NSString stringWithFormat:#"%# %i%# %# - %#", dateDay, dateOfDay, dateScript, dateMonth, days == 0 ? bToday : bYesterday];
}
else {
header = [NSString stringWithFormat:#"%# %i%# %# - %i %#", dateDay, dateOfDay, dateScript, dateMonth, days, bDaysAgo];
}
return header;
}
}
At the moment this outputs it like this:
|Wed 4th Dec - Today________|
I want it to be like this:
|Wed 4th Dec_________Today|
You can't do it with titleForHeaderInSection. You would need to implement viewForHeaderInSection instead. Return a view with two labels - one to the left and one to the right. Of course you view would also need to replicate the default look of a standard table section header if that's what you want.

NSDate to Tick conversion

I wanted to convert a date (nsdate) to tick values. Tick values are (1 Tick = 0.1 microseconds or 0.0001 milliseconds) since 1 Jan 0001 00:00:00 GMT. NSDate has functions like timeIntervalSince1970. So, how do I convert it?
I would like to share my experience:
I tried to find the seconds from 01/01/0001 and then multiply by 10,000,000. However, it gave me wrong results. So, I found out that 01/01/1970 is 621355968000000000 ticks from 01/01/0001 and used the following formula along with timeIntervalSince1970 function of NSDate.
Ticks = (MilliSeconds * 10000) + 621355968000000000
MilliSeconds = (Ticks - 621355968000000000) / 10000
Here is the outcome:
+(NSString *) dateToTicks:(NSDate *) date
{
NSString *conversionDateStr = [self dateToYYYYMMDDString:date];
NSDate *conversionDate = [self stringYYYYMMDDToDate:conversionDateStr];
NSLog(#"%#",[date description]);
NSLog(#"%#",[conversionDate description]);
double tickFactor = 10000000;
double timeSince1970 = [conversionDate timeIntervalSince1970];
double doubleValue = (timeSince1970 * tickFactor ) + 621355968000000000;
NSNumberFormatter *numberFormatter = [[[NSNumberFormatter alloc] init] autorelease];
[numberFormatter setNumberStyle:NSNumberFormatterNoStyle];
NSNumber *nsNumber = [NSNumber numberWithDouble:doubleValue];
return [numberFormatter stringFromNumber:nsNumber];
}
Likewise, to convert from tick to date:
//MilliSeconds = (Ticks - 621355968000000000) / 10000
+(NSDate *) ticksToDate:(NSString *) ticks
{
double tickFactor = 10000000;
double ticksDoubleValue = [ticks doubleValue];
double seconds = ((ticksDoubleValue - 621355968000000000)/ tickFactor);
NSDate *returnDate = [NSDate dateWithTimeIntervalSince1970:seconds];
NSLog(#"%#",[returnDate description]);
return returnDate;
}

iOS - Friendly NSDate format

I need to display the date of posts in my app to the user, right now I do it in this format: "Fri, 25 May". How would I format an NSDate to read something like "2 hours ago"? To make it more user friendly.
Take a look at FormaterKit https://github.com/mattt/FormatterKit
Created by mattt who also created AFNetworking.
NSDateFormatter can't do things like that; you're going to need to establish your own rules. I guess something like:
- (NSString *)formattedDate:(NSDate *)date
{
NSTimeInterval timeSinceDate = [[NSDate date] timeIntervalSinceDate:date];
// print up to 24 hours as a relative offset
if(timeSinceDate < 24.0 * 60.0 * 60.0)
{
NSUInteger hoursSinceDate = (NSUInteger)(timeSinceDate / (60.0 * 60.0));
switch(hoursSinceDate)
{
default: return [NSString stringWithFormat:#"%d hours ago", hoursSinceDate];
case 1: return #"1 hour ago";
case 0:
NSUInteger minutesSinceDate = (NSUInteger)(timeSinceDate / 60.0);
/* etc, etc */
break;
}
}
else
{
/* normal NSDateFormatter stuff here */
}
}
So that's to print 'x minutes ago' or 'x hours ago' up to 24 hours from the date, which will usually be one day.
I wanted a date format like Facebook does for their mobile apps so I whipped up this NSDate category - hope it is useful for someone (this kind of stuff should really be in a standard library!) :)
https://github.com/nikilster/NSDate-Time-Ago
There's also SEHumanizedTimeDiff which does/is about to support multiple languages if that's an issue for you:
https://github.com/sarperdag/SEHumanizedTimeDiff
There are about a million ways you could do this, but here's a quick one:
NSString* hoursAgo = [NSString stringWithFormat:#"%.0lf hours ago", fabs([date timeIntervalSinceNow] / 3600.0)]
Of course, this doesn't check that date is actually from the past, doesn't do anything but hours, etc. But, you probably get the idea.
timeIntervalSinceNow returns how many seconds have passed since a given date, with positive numbers being a date in the future and negative numbers being a date in the past. So, we get how many seconds have passed, divide it by 3600 seconds in an hour to compute the hours that have passed, and then put its absolute value into the string "n hours ago".
Here is a pretty good answer this will take in seconds since the epoch(Jan 1, 1970) and return you a nice formatted string like '3 minutes ago'. Simply call it with your date object like so:
[timeAgoFromUnixTime:[myDateObject timeIntervalSince1970]];
+ (NSString *)timeAgoFromUnixTime:(double)seconds
{
double difference = [[NSDate date] timeIntervalSince1970] - seconds;
NSMutableArray *periods = [NSMutableArray arrayWithObjects:#"second", #"minute", #"hour", #"day", #"week", #"month", #"year", #"decade", nil];
NSArray *lengths = [NSArray arrayWithObjects:#60, #60, #24, #7, #4.35, #12, #10, nil];
int j = 0;
for(j=0; difference >= [[lengths objectAtIndex:j] doubleValue]; j++)
{
difference /= [[lengths objectAtIndex:j] doubleValue];
}
difference = roundl(difference);
if(difference != 1)
{
[periods insertObject:[[periods objectAtIndex:j] stringByAppendingString:#"s"] atIndex:j];
}
return [NSString stringWithFormat:#"%li %#%#", (long)difference, [periods objectAtIndex:j], #" ago"];
}
In newer versions of iOS since this question was asked, NSDateFormatter has had this ability added. It can now do it using the doesRelativeDateFormatting property.
+(NSString*)HourCalculation:(NSString*)PostDate
{
NSLog(#"postdate=%#",PostDate);
// PostDate=#"2014-04-02 01:31:04";
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:#"yyyy-MM-dd HH:mm:ss"];
NSTimeZone *gmt = [NSTimeZone timeZoneWithAbbreviation:#"GMT"];
[dateFormat setTimeZone:gmt];
NSDate *ExpDate = [dateFormat dateFromString:PostDate];
NSLog(#"expdate=%#",ExpDate);
NSLog(#"expdate=%#",[NSDate date ]);
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *components = [calendar components:(NSDayCalendarUnit|NSWeekCalendarUnit|NSMonthCalendarUnit|NSYearCalendarUnit|NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit) fromDate:ExpDate toDate:[NSDate date] options:0];
// NSLog(#"year=%d",components.year);
//
// NSLog(#"month=%d",components.month);
//
// NSLog(#"week=%d",components.week);
//
// NSLog(#"day=%d",components.day);
//
// NSLog(#"hour=%d",components.hour);
//
// NSLog(#"min=%d",components.minute);
//
// NSLog(#"sce=%d",components.second);
//
NSString *time;
if(components.year!=0)
{
if(components.year==1)
{
time=[NSString stringWithFormat:#"%ld year",(long)components.year];
}
else{
time=[NSString stringWithFormat:#"%ld years",(long)components.year];
}
}
else if(components.month!=0)
{
if(components.month==1)
{
time=[NSString stringWithFormat:#"%ld month",(long)components.month];
}
else{
time=[NSString stringWithFormat:#"%ld months",(long)components.month];
}
// NSLog(#"%#",time);
}
else if(components.week!=0)
{
if(components.week==1)
{
time=[NSString stringWithFormat:#"%ld week",(long)components.week];
}
else{
time=[NSString stringWithFormat:#"%ld weeks",(long)components.week];
}
// NSLog(#"%#",time);
}
else if(components.day!=0)
{
if(components.day==1)
{
time=[NSString stringWithFormat:#"%ld day",(long)components.day];
}
else{
time=[NSString stringWithFormat:#"%ld days",(long)components.day];
}
}
else if(components.hour!=0)
{
if(components.hour==1)
{
time=[NSString stringWithFormat:#"%ld hour",(long)components.hour];
}
else{
time=[NSString stringWithFormat:#"%ld hours",(long)components.hour];
}
}
else if(components.minute!=0)
{
if(components.minute==1)
{
time=[NSString stringWithFormat:#"%ld min",(long)components.minute];
}
else{
time=[NSString stringWithFormat:#"%ld mins",(long)components.minute];
}
// NSLog(#"time=%#",time);
}
else if(components.second>=0){
// NSLog(#"postdate=%#",PostDate);
// NSLog(#"expdate=%#",[NSDate date ]);
if(components.second==0)
{
time=[NSString stringWithFormat:#"1 sec"];
}
else{
time=[NSString stringWithFormat:#"%ld secs",(long)components.second];
}
}
return [NSString stringWithFormat:#"%# ago",time];
}
This code will show you time in
------------sec like 2 sec ago
------------min like 2 mins ago
------------hours like 2 hours ago
------------days like 2 days ago
------------week like 2 weeks ago
------------month like 2 months ago
Lastly....
years like 2 years ago
:) try this
Adding to the solution try this more simplified method
NSDateComponents *today = [[NSCalendar currentCalendar] components:NSCalendarUnitDay|NSCalendarUnitHour|NSCalendarUnitMinute|NSCalendarUnitSecond fromDate:passed toDate:[NSDate date] options:0];
NSTimeInterval interval = [[NSDate date] timeIntervalSinceDate:date];
if (interval < 60) timestampString = [NSString stringWithFormat:#"%d seconds ago" ,today.second];
else if (interval < 60 * 60) timestampString = [NSString stringWithFormat:#"%d minutes ago" ,today.minute];
else if (interval < 60 * 60 * 24) timestampString = [NSString stringWithFormat:#"%d hours ago" ,today.hour];
else timestampString = [NSString stringWithFormat:#"%d days ago" ,today.day];

Resources