Custom Date and Time Format Strings : DateTimeFormatInfo « Date Time « C# / C Sharp






Custom Date and Time Format Strings

  
using System;
using System.Globalization;


public class MainClass
{
    public static void Main()
    {
        DateTime thisDate1 = new DateTime(2011, 6, 10);
        Console.WriteLine("Today is " + thisDate1.ToString("MMMM dd, yyyy") + ".");

        DateTimeOffset thisDate2 = new DateTimeOffset(2011, 6, 10, 15, 24, 16, TimeSpan.Zero);
        Console.WriteLine("The current date and time: {0:MM/dd/yy H:mm:ss zzz}", thisDate2);
    }
}

//Today is June 10, 2011.
//The current date and time: 06/10/11 15:24:16 +00:00

   
    
  








Related examples in the same category

1.CultureInfo Provides information about a specific culture
2.Determines the specific cultures that use the Chinese language, and displays the parent culture
3.Gets or sets a DateTimeFormatInfo that defines the culturally appropriate format of displaying dates and times.
4.Gets the list of calendars that can be used by the culture.
5.DateTimeFormatInfo Class
6.DateTimeFormatInfo.AbbreviatedMonthGenitiveNames
7.DateTimeFormatInfo.FullDateTimePattern
8.ALL the patterns
9.DateTimeFormatInfo.LongDatePattern
10.DateTimeFormatInfo.LongTimePattern
11.DateTimeFormatInfo.MonthDayPattern
12.DateTimeFormatInfo.RFC1123Pattern
13.DateTimeFormatInfo.ShortDatePattern
14.DateTimeFormatInfo.ShortTimePattern
15.DateTimeFormatInfo.SortableDateTimePattern
16.DateTimeFormatInfo.UniversalSortableDateTimePattern
17.DateTimeFormatInfo.YearMonthPattern
18.To Short Date Time
19.To Date Time from dmtf date