Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Convert date into specific day of week

    • 0
    • 1
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 392
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: