Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Add Suffix To Date

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 180
    Comment on it

                     Add Suffix To Date

    Here is a very simple example of adding suffix to the date in iOS .With the help of example given below you can easily add a suffix to the date selected by the NSCalender class.

    + (NSString )addSuffixToDate:(NSDate )date {
        NSCalendar *calendar = [NSCalendar currentCalendar];
        NSInteger currentDay = [calendar component:NSCalendarUnitDay fromDate:date];
        switch (currentDay ) {
            case 1:
            case 21:
            case 31: return @"ST";
            case 2:
            case 22: return @"ND";
            case 3:
            case 23: return @"RD";
            default: return @"TH";
        }
    }


    First of all object of NSCalender class is created for accessing further components related to this class. After that with the help of integer variable currentDay we are fetching the day from the whole date. If the day which is returned by variable currentDay of NSInteger class is 1,21 and 31 than suffix “ST” will be added simultaneously for day 2 and 22 suffix “ND” will be added in continuation for day 3 and 23 suffix “RD” will be added and rest of the day will be added by suffix “TH”.

 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: