Ordinal DateFormate Like - "11th" , "21st" in swift.

An Ordinal Number is the position of the number list such as 1st, 2nd , 3rd , 4th, 5th, 6th etc. Means ordinal number ends with "st", "nd" , "rd" , and "th".

An Ordinal Number is a number that tells the position of something in a list, such as 1st, 2nd, 3rd, 4th, 5th etc. Most ordinal numbers end in "th" except for: one ⇒ first (1st) two ⇒ second (2nd) three ⇒ third (3rd).

Original Date : 2016-02-05

Ordinal Date : 5th Feb , 2016

How to convert date to ordinal number in iOS.
func convertDateFormate(date : NSDate) -> String{

        let dateFormate1 = NSDateFormatter()
        dateFormate1.dateFormat = "MMM, yyyy"
        let dateN1 = dateFormate1.stringFromDate(date)

        var days = (date as NSString).substringFromIndex(date.characters.count-2)
        switch (days) {
        case "1":
        case "2":
        case "3":

        return days + " " + dateN1
Use the above function as below code.
// Current Date
let myCurrentDate = self.convertDateFormate(NSDate())


Ordinal DateFormate Like - "11th" , "21st" in swift. Ordinal DateFormate Like - "11th" , "21st" in swift. Reviewed by Kirit Modi on 21:54:00 Rating: 5

No comments:

Powered by Blogger.