C# DateTime.GetDateTimeFormats() Method with Example

DateTime.GetDateTimeFormats() Method: Here, we will find out about the GetDateTimeFormats() technique for DateTime class with example in C#.

DateTime.GetDateTimeFormats() Method

DateTime.GetDateTimeFormats() strategy is utilized to get every single imaginable organization of date-time.

Syntax:

string[] DateTime.GetDateTimeFormates(DateTime dt);

Parameter(s):

DateTime dt – it speaks to the date/time.

Return value:

The arrival sort of this technique is string[], it restores the variety of strings class that contains the all conceivable date-time positions.

Example to show example of DateTime.GetDateTimeFormats() strategy

using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create object of datetime class
            DateTime dt1 = new DateTime(2019,1,1,10,10,10);
            
            //Get all date time formate in string array.
            string []str =dt1.GetDateTimeFormats();

            //Print all formates.
            foreach (string format in str)
            {
                Console.WriteLine(format);
            }

            Console.WriteLine();  
        }
    }
}

Output

1/1/2019
1/1/19
01/01/19
01/01/2019
19/01/01
2019-01-01
01-Jan-19
Tuesday, January 01, 2019
January 01, 2019
Tuesday, 01 January, 2019
01 January, 2019
Tuesday, January 01, 2019 10:10 AM
Tuesday, January 01, 2019 10:10 AM
Tuesday, January 01, 2019 10:10
Tuesday, January 01, 2019 10:10
January 01, 2019 10:10 AM
January 01, 2019 10:10 AM
January 01, 2019 10:10
January 01, 2019 10:10
Tuesday, 01 January, 2019 10:10 AM
Tuesday, 01 January, 2019 10:10 AM
Tuesday, 01 January, 2019 10:10
Tuesday, 01 January, 2019 10:10
01 January, 2019 10:10 AM
01 January, 2019 10:10 AM
01 January, 2019 10:10
01 January, 2019 10:10
Tuesday, January 01, 2019 10:10:10 AM
Tuesday, January 01, 2019 10:10:10 AM
Tuesday, January 01, 2019 10:10:10
Tuesday, January 01, 2019 10:10:10
January 01, 2019 10:10:10 AM
January 01, 2019 10:10:10 AM
January 01, 2019 10:10:10
January 01, 2019 10:10:10
Tuesday, 01 January, 2019 10:10:10 AM
Tuesday, 01 January, 2019 10:10:10 AM
Tuesday, 01 January, 2019 10:10:10
Tuesday, 01 January, 2019 10:10:10
01 January, 2019 10:10:10 AM
01 January, 2019 10:10:10 AM
01 January, 2019 10:10:10
01 January, 2019 10:10:10
1/1/2019 10:10 AM
1/1/2019 10:10 AM
1/1/2019 10:10
1/1/2019 10:10
1/1/19 10:10 AM
1/1/19 10:10 AM
1/1/19 10:10
1/1/19 10:10
01/01/19 10:10 AM
01/01/19 10:10 AM
01/01/19 10:10
01/01/19 10:10
01/01/2019 10:10 AM
01/01/2019 10:10 AM
01/01/2019 10:10
01/01/2019 10:10
19/01/01 10:10 AM
19/01/01 10:10 AM
19/01/01 10:10
19/01/01 10:10
2019-01-01 10:10 AM
2019-01-01 10:10 AM
2019-01-01 10:10
2019-01-01 10:10
01-Jan-19 10:10 AM
01-Jan-19 10:10 AM
01-Jan-19 10:10
01-Jan-19 10:10
1/1/2019 10:10:10 AM
1/1/2019 10:10:10 AM
1/1/2019 10:10:10
1/1/2019 10:10:10
1/1/19 10:10:10 AM
1/1/19 10:10:10 AM
1/1/19 10:10:10
1/1/19 10:10:10
01/01/19 10:10:10 AM
01/01/19 10:10:10 AM
01/01/19 10:10:10
01/01/19 10:10:10
01/01/2019 10:10:10 AM
01/01/2019 10:10:10 AM
01/01/2019 10:10:10
01/01/2019 10:10:10
19/01/01 10:10:10 AM
19/01/01 10:10:10 AM
19/01/01 10:10:10
19/01/01 10:10:10
2019-01-01 10:10:10 AM
2019-01-01 10:10:10 AM
2019-01-01 10:10:10
2019-01-01 10:10:10
01-Jan-19 10:10:10 AM
01-Jan-19 10:10:10 AM
01-Jan-19 10:10:10
01-Jan-19 10:10:10
January 01
January 01
2019-01-01T10:10:10.0000000
2019-01-01T10:10:10.0000000
Tue, 01 Jan 2019 10:10:10 GMT
Tue, 01 Jan 2019 10:10:10 GMT
2019-01-01T10:10:10
10:10 AM
10:10 AM
10:10
10:10
10:10:10 AM
10:10:10 AM
10:10:10
10:10:10
2019-01-01 10:10:10Z
Tuesday, January 01, 2019 4:40:10 AM
Tuesday, January 01, 2019 04:40:10 AM
Tuesday, January 01, 2019 4:40:10
Tuesday, January 01, 2019 04:40:10
January 01, 2019 4:40:10 AM
January 01, 2019 04:40:10 AM
January 01, 2019 4:40:10
January 01, 2019 04:40:10
Tuesday, 01 January, 2019 4:40:10 AM
Tuesday, 01 January, 2019 04:40:10 AM
Tuesday, 01 January, 2019 4:40:10
Tuesday, 01 January, 2019 04:40:10
01 January, 2019 4:40:10 AM
01 January, 2019 04:40:10 AM
01 January, 2019 4:40:10
01 January, 2019 04:40:10
January, 2019
January, 2019

Leave a Comment

error: Alert: Content is protected!!