Skip to content

Instantly share code, notes, and snippets.

@ChauThan
Created June 19, 2018 07:12
Show Gist options
  • Save ChauThan/0aa9dacf7512e43448a76ef19cb404ea to your computer and use it in GitHub Desktop.
Save ChauThan/0aa9dacf7512e43448a76ef19cb404ea to your computer and use it in GitHub Desktop.
[Humanized Date] #CSharp #DateTime #Format
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