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

前端 未结 11 1349
一生所求
一生所求 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:40

    You can add the TimeSpan to a DateTime, for example:

    TimeSpan span = TimeSpan.FromHours(16);
    DateTime time = DateTime.Today + span;
    String result = time.ToString("hh:mm tt");
    

    Demo: http://ideone.com/veJ6tT

    04:00 PM
    

    Standard Date and Time Format Strings

提交回复
热议问题