What is the string format options for AM and PM in DateTime with C#

1 Answer

0 votes
using System;
  
public class Program
{
    public static void Main()
    {
        DateTime dt = new DateTime(2004, 03, 06, 17, 30, 07, 235);

        string s = String.Format("{0:t tt}", dt);          
        Console.WriteLine(s);
        
        dt = new DateTime(2004, 03, 06, 1, 30, 07, 235);
        s = String.Format("{0:t tt}", dt);          
        Console.WriteLine(s);
    }
}
  
  
  
  
/*
run:
  
P PM
A AM
  
*/

 



answered Mar 27, 2022 by avibootz
edited Mar 27, 2022 by avibootz

Related questions

1 answer 186 views
1 answer 170 views
1 answer 205 views
1 answer 164 views
1 answer 176 views
1 answer 179 views
...