-(NSDate)dateDiff:(double )myCaldDate
{
/ Date difference for the purpose of showing games listes
double timeInterval = myCaldDate/1000.0f;
NSDate *convertedDate = [NSDate dateWithTimeIntervalSince1970:timeInterval];
return convertedDate;
}
Now Sync :-
-(NSString *)syncWithCalender:(NSDate *)convertDate
{
NSDate *todayDate = [NSDate date];
double ti = [convertDate timeIntervalSinceDate:todayDate];
ti = ti * -1;
if(ti <= 1)
{
return @"Just Now";
}
else if (ti < 60)
{
return @"less than a minute ago";
}
else if (ti < 3600)
{
int diff = (ti / 60);
if (diff==1)
{
return [NSString stringWithFormat:@"%d minute ago", diff];
}
return [NSString stringWithFormat:@"%d minutes ago", diff];
}
else if (ti < 86400)
{
int diff = (ti / 60 / 60);
if (diff == 1)
{
return[NSString stringWithFormat:@"%d hour ago", diff];
}
return[NSString stringWithFormat:@"%d hours ago", diff];
}
else if (ti < 2629743)
{
int diff = (ti / 60 / 60 / 24);
if (diff == 1)
{
return[NSString stringWithFormat:@"%d day ago", diff];
}
return[NSString stringWithFormat:@"%d days ago", diff];
}
else if (ti < 31557600)
{
int diff = (ti / 60 / 60 / 24 / 30);
if (diff == 1)
{
return[NSString stringWithFormat:@"%d month ago", diff];
}
return[NSString stringWithFormat:@"%d months ago", diff];
}
else
{
int diff = (ti / 60 / 60 / 24 / 30 / 12);
if (diff == 1)
{
return[NSString stringWithFormat:@"%d year ago", diff];
}
return[NSString stringWithFormat:@"%d years ago", diff];
}
}