DateTime format

class Program
{
    public static void Main(string[] args)
    {
        DateTime thisDate = DateTime.Now;
        //Standard Time Formatting
 
        //Pattern 1: dd/MM/yyyy
        Console.WriteLine("Pattern 1: Today is in dd/MM/yyyy format :" + thisDate.ToString("dd/MM/yyyy"));//18/09/2016
 
        //Pattern 2: dd-MM-yyyy
        Console.WriteLine("Pattern 2: Today is in dd-MM-yyyy format :" + thisDate.ToString("dd-MM-yyyy"));//18-09-2016
 
        //Pattern 3: yyyy-MM-dd
        Console.WriteLine("Pattern 3: Today is in yyyy-MM-dd format :" + thisDate.ToString("yyyy-MM-dd"));//2016-09-18
 
        //Pattern 4: dd MMMM yyyy
        Console.WriteLine("Pattern 4: Today is in dd MMMM yyyy format :" + thisDate.ToString("dd MMMM yyyy"));//18 September 2016
 
        //Pattern 5: short Time {0:t}
        Console.WriteLine("Pattern 5: Time in {0:t} format :" + String.Format("{0:t}", thisDate));//10:26 PM
 
        //Pattern 6: {0:d} shortdate
        Console.WriteLine("Pattern 6: Today is in {0:d} format :" + String.Format("{0:d}", thisDate));//9/18/2016
 
        //Pattern 7: {0:T} long time
        Console.WriteLine("Pattern 7: Today is in {0:T} format :" + String.Format("{0:T}", thisDate));//10:26:35PM
 
        //Pattern 8: {0:D} Long Date
        Console.WriteLine("Pattern 8: Today is in {0:D} format :" + String.Format("{0:D}", thisDate));//September 18, 2016
 
        //Pattern 9: {0:f} Longdate & short time
        Console.WriteLine("Pattern 9: Today is in {0:f} format :" + String.Format("{0:f}", thisDate));//September 18, 2016 10:26 PM
 
        //Pattern 10: {0:F} Full date Time
        Console.WriteLine("Pattern 10: Today is in {0:F} format :" + String.Format("{0:F}", thisDate));//September 18, 2016 10:26:35PM
 
        //Pattern 11: {0:g} Shortdate & Short Time
        Console.WriteLine("Pattern 11: Today is in {0:g} format :" + String.Format("{0:g}", thisDate));//9/18/2016 22:26 PM
 
        //Pattern 12: {0:G} Shortdate & Long Time
        Console.WriteLine("Pattern 12: Today is in {0:G} format :" + String.Format("{0:G}", thisDate));//9/18/2016 22:26:35 PM
 
        //Pattern 13: {0:m} Month Day
        Console.WriteLine("Pattern 13: Today is in {0:m} format :" + String.Format("{0:m}", thisDate));//September 18
 
        //Pattern 14: {0:y} Year Month
        Console.WriteLine("Pattern 14: Today is in {0:y} format :" + String.Format("{0:y}", thisDate));//September,2016
 
        //Pattern 15: {0:r}
        Console.WriteLine("Pattern 15:Today is in {0:r} format :" + String.Format("{0:r}", thisDate));//18 Sep 2016 22:26:35 GMT
 
        //Pattern 16: Time {0:s} sortable datetime
        Console.WriteLine("Pattern 16:Today is in {0:s} format :" + String.Format("{0:s}", thisDate));//2016-09-18T22:26:35
 
        //Pattern 17: Time {0:u} Univerasal Sortdate time
        Console.WriteLine("Pattern 17: Today is in {0:u} format :" + String.Format("{0:u}", thisDate));//2016-09-18 22:26:35Z
        
        //Custom Datetime Formatting
 
        // Pattern 18: month/day numbers without/with leading zeroes
        Console.WriteLine("Pattern 18: Today is in {0:M/d/yyyy} format:" + String.Format("{0:M/d/yyyy}", thisDate)); //9/18/2016          
        Console.WriteLine("Pattern 18: Today is in {0:MM/dd/yyyy} format:" + String.Format("{0:MM/dd/yyyy}", thisDate));//09/18/2016
 
        // Pattern 19: day/month names
        Console.WriteLine("Pattern 19: Today is in {0:ddd, MMM d, yyyy} format:" + String.Format("{0:ddd, MMM d, yyyy}", thisDate));//Sun,Sep 18, 2016
        Console.WriteLine("Pattern 19: Today is in {0:dddd, MMMM d, yyyy} format:" + String.Format("{0:dddd, MMMM d, yyyy}", thisDate));//Sunday,September 18, 2016
 
       // Pattern 20: two/four digit year
        Console.WriteLine("Pattern 20: Today is in {0:MM/dd/yy} format:" + String.Format("{0:MM/dd/yy}", thisDate));//09/18/16
        Console.WriteLine("Pattern 20: Today is in {0:MM/dd/yyyy} format:" + String.Format("{0:MM/dd/yyyy}", thisDate));//09/18/2016
 
        // Pattern 21: {0:y yy yyy yyyy}
        Console.WriteLine("Pattern 21: year {0:y yy yyy yyyy} format:" + String.Format("{0:y yy yyy yyyy}", thisDate));//16 16 2016 2016
 
        // Pattern 22: {0:M MM MMM MMMM}
        Console.WriteLine("Pattern 22: Month {0:M MM MMM MMMM} format:" + String.Format("{0:M MM MMM MMMM}", thisDate));//9 09 Sep September
 
        // Pattern 23: {0:d dd ddd dddd}
        Console.WriteLine("Pattern 23: Day {0:d dd ddd dddd} format:" + String.Format("{0:d dd ddd dddd}", thisDate));//18 18 Sun Sunday
 
        // Pattern 24: {0:h hh H HH}
        Console.WriteLine("Pattern 24: Hour {0:h hh H HH} format:" + String.Format("{0:h hh H HH}", thisDate));//10 10 22 22
 
        // Pattern 25: {0:m mm}
        Console.WriteLine("Pattern 25: Minute {0:m mm} format:" + String.Format("{0:m mm}", thisDate));//26 26
 
        // Pattern 26: {0:s ss}
        Console.WriteLine("Pattern 26: Sec {0:s ss} format:" + String.Format("{0:s ss}", thisDate));//35 35
 
        // Pattern 27: {0:f ff fff ffff}
        Console.WriteLine("Pattern 27: Sec fraction {0:f ff fff ffff} format:" + String.Format("{0:f ff fff ffff}", thisDate));//9 94 946 9465
 
        // Pattern 28: {0:h hh H HH}"
        Console.WriteLine("Pattern 28: Sec {0:F FF FFF FFFF} format:" + String.Format("{0:F FF FFF FFFF}", thisDate));//9 94 946 9465
 
        // Pattern 29: {0:t tt} 
        Console.WriteLine("Pattern 29: AM or PM  {0:t tt} format:" + String.Format("{0:t tt}", thisDate)); // P PM
 
        // Pattern 30: Timezone {0:z zz zzz}
        Console.WriteLine("Pattern 30: timeZone {0:z zz zzz} format:" + String.Format("{0:z zz zzz}", thisDate)); // -4 -04 -04:00
    }
}

Kaynak