Convert time span value to format “hh:mm Am/Pm” using C#

前端 未结 11 1352
一生所求
一生所求 2020-11-28 07:22

I have a value stored in variable of type System.TimeSpan as follows.

System.TimeSpan storedTime = 03:00:00;

Can I re-store it

11条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-28 07:47

    You can try this:

       string timeexample= string.Format("{0:hh:mm:ss tt}", DateTime.Now);
    

    you can remove hh or mm or ss or tt according your need where hh is hour in 12 hr formate, mm is minutes,ss is seconds,and tt is AM/PM.

提交回复
热议问题