The following code is to convert day into specific day of week like Sunday , Monday , today , tomorrow etc. and after 7 days you want to show only that date, then this code will help you.
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"dd-MM-yy"];
serDate = datePicker.date;
endDate = [NSDate date];
NSTimeInterval distanceBetweenDates = [serDate timeIntervalSinceDate:endDate];
double secondsInAnHour = 3600;
NSInteger hoursBetweenDates = distanceBetweenDates / secondsInAnHour;
NSLog(@"time slice == %d",hoursBetweenDates);
if ((hoursBetweenDates <= -24)&&(hoursBetweenDates >= -48)) {
dateText.text = @"Yesterday";
}else if ((hoursBetweenDates >= -24)&&(hoursBetweenDates <= 0)){
dateText.text = @"Today";
}else if ((hoursBetweenDates > 0)&&(hoursBetweenDates <= 24)){
dateText.text = @"Tomorrow";
}else if ((hoursBetweenDates >= 24)&&(hoursBetweenDates <= 148)){
dateText.text = [self stringFromDate:serDate format:@"EEEE"];
}else{
dateText.text = [self stringFromDate:serDate format:@"dd-MM-yy"];
}
0 Comment(s)