Created
November 12, 2018 19:46
-
-
Save SalesforceBobLightning/0605958a30cf5841491b4ef20aa9c57e to your computer and use it in GitHub Desktop.
Salesforce Apex Datetime Utils
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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