Home » C#

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#.
Submitted by IncludeHelp, on October 22, 2019

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

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.