Last active
January 6, 2016 08:06
-
-
Save elizabeth-young/5362631 to your computer and use it in GitHub Desktop.
Full date string methods
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 static class DateSuffixHelper | |
{ | |
public static string FullDate(DateTime date) | |
{ | |
return date.ToString("%d") + DaySuffix(date.Day) + date.ToString(" MMMM yyyy"); | |
} | |
public static string FullDateIncDay(DateTime date) | |
{ | |
return date.ToString("dddd d") + DaySuffix(date.Day) + date.ToString(" MMMM yyyy"); | |
} | |
public static string FullDateIncDayAndTime(DateTime date) | |
{ | |
return date.ToString("dddd d") + DaySuffix(date.Day) + date.ToString(" MMMM yyyy - HH:mm"); | |
} | |
public static string AbrDateIncDayAndTime(DateTime date) | |
{ | |
return date.ToString("ddd d") + DaySuffix(date.Day) + date.ToString(" MMM yyyy - HH:mm"); | |
} | |
private static string DaySuffix(int day) | |
{ | |
switch (day) | |
{ | |
case 1: | |
case 21: | |
case 31: | |
return "st"; | |
case 2: | |
case 22: | |
return "nd"; | |
case 3: | |
case 23: | |
return "rd"; | |
default: | |
return "th"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment