C# | DateTime.GetDateTimeFormats() Method with Example

DateTime.GetDateTimeFormats() Method: Here, we are going to learn about the GetDateTimeFormats() method of DateTime class with example in C#. By IncludeHelp Last updated : August 27, 2023

C# DateTime.GetDateTimeFormats() Method

DateTime.GetDateTimeFormats() method is used to get all possible formats of date-time.

Syntax

string[] DateTime.GetDateTimeFormates(DateTime dt);

Parameter(s)

  • DateTime dt – it represents the date/time.

Return value

The return type of this method is string[], it returns the array of strings class that contains the all possible date-time formats.

Example to demonstrate example of DateTime.GetDateTimeFormats() method

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

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.