How to convert today's date and time to string with different formats switch C#

1 Answer

0 votes
using System;

class Program
{
    static void Main() {
        DateTime now = DateTime.Now;
        
        Console.WriteLine("1. " + now.ToString("d"));
        Console.WriteLine("2. " + now.ToString("D"));
        Console.WriteLine("3. " + now.ToString("F"));
        Console.WriteLine("4. " + now.ToString("M"));
        Console.WriteLine("5. " + now.ToString("o"));
        Console.WriteLine("6. " + now.ToString("R"));
        Console.WriteLine("7. " + now.ToString("t"));
        Console.WriteLine("8. " + now.ToString("T"));
        Console.WriteLine("9. " + now.ToString("Y"));
    }
}




/*
run:

1. 7/8/2023
2. Saturday, July 8, 2023
3. Saturday, July 8, 2023 6:26:31 AM
4. July 8
5. 2023-07-08T06:26:31.3717340+00:00
6. Sat, 08 Jul 2023 06:26:31 GMT
7. 6:26 AM
8. 6:26:31 AM
9. July 2023

*/

 



answered Jul 8, 2023 by avibootz
...