How do I get the AM/PM value from a DateTime?

后端 未结 14 1602
刺人心
刺人心 2020-11-28 06:23

The code in question is below:

public static string ChangePersianDate(DateTime dateTime)
{
    System.Globalization.GregorianCalendar PC = new System.Globa         


        
14条回答
  •  情歌与酒
    2020-11-28 07:09

    Here is an easier way you can write the time format (hh:mm:ss tt) and display them separately if you wish.

    string time = DateTime.Now.Hour.ToString("00") + ":" + DateTime.Now.Minute.ToString("00") + ":" + DateTime.Now.Second.ToString("00") + DateTime.Now.ToString(" tt");
    

    or just simply:

     DateTime.Now.ToString("hh:mm:ss tt")
    

提交回复
热议问题