Created
June 19, 2018 07:12
-
-
Save ChauThan/0aa9dacf7512e43448a76ef19cb404ea to your computer and use it in GitHub Desktop.
[Humanized Date] #CSharp #DateTime #Format
This file contains hidden or 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
internal static string HumanisedDate(this DateTime date) | |
{ | |
string ordinal; | |
switch (date.Day) | |
{ | |
case 1: | |
case 21: | |
case 31: | |
ordinal = "st"; | |
break; | |
case 2: | |
case 22: | |
ordinal = "nd"; | |
break; | |
case 3: | |
case 23: | |
ordinal = "rd"; | |
break; | |
default: | |
ordinal = "th"; | |
break; | |
} | |
return string.Format("{0:dddd dd}{1} {0:MMMM yyyy}", date, ordinal); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment