How do I convert current date with ordinal suffix?

HELP!

How do I convert current date with ordinal suffix? i.e 1st/01/2020

  • For days 1, 21, 31 it will show 1st, 21st, 31st
  • For days 2, 22 it will show 2nd, 22nd
  • For day 3, 23 it will show 3rd, 23rd
  • For the rest of the days it will end with a “th” (e.g. 5th)

Many thanks!!!

@april How about taking a look at these ideas:

Summary

I chose one of the methods and put this together.

def todaysDate = new Date();

def dayPart = todaysDate[Calendar.DAY_OF_MONTH];
def myPart = todaysDate.format('MM/yyyy');
def ordDate = '';
def dayDate = '';

switch (dayPart) {
     case 1:  case 21:  case 31:
          dayDate = dayPart.toString() + "st";
          break;
      case 2: case 22:
          dayDate = dayPart.toString() + "nd";
          break;
      case 3: case 23:
          dayDate = dayPart.toString() + "rd";
          break;
      default:
          dayDate = dayPart.toString() + "th";
          break;
}

ordDate =  dayDate + "/" + myPart;

println('ordinal date is ' + ordDate);