display timespan nicely

前端 未结 4 2244
心在旅途
心在旅途 2021-02-19 01:48

Excuse the rough code, I\'m trying to display the duration of videos given the time in seconds. I\'ve had a go below but it\'s not working properly.

I want it to just d

4条回答
  •  一个人的身影
    2021-02-19 02:27

    I think you can simplify this by removing the "D2" aspect of the format and then you won't need a special case for the under ten minutes option. Basically just using

    string.Format("{0}m:{1}s", t.Minutes, t.Seconds);
    

    will get you one or two digits as required. So your final case is:

    string.Format("{0}h:{1}m:{2}s", t.Hours, t.Minutes, t.Seconds);
    

提交回复
热议问题