Skip to content

Instantly share code, notes, and snippets.

@SalesforceBobLightning
Created November 12, 2018 19:46
Show Gist options
  • Save SalesforceBobLightning/0605958a30cf5841491b4ef20aa9c57e to your computer and use it in GitHub Desktop.
Save SalesforceBobLightning/0605958a30cf5841491b4ef20aa9c57e to your computer and use it in GitHub Desktop.
Salesforce Apex Datetime Utils
public without sharing class DatetimeUtils {
public static String getDayOfMonthSuffix(Integer n) {
if (n == null) {
return '';
}
if (n >= 11 && n <= 13) {
return 'th';
}
Integer modResult = Math.mod(n, 10);
if (modResult == 1) {
return 'st';
} else if (modResult == 2) {
return 'nd';
} else if (modResult == 3) {
return 'rd';
} else {
return 'th';
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment