How to format the HH:mm:ss separators of a TimeSpan in a culture-aware manner?

前端 未结 3 1264
谎友^
谎友^ 2021-01-05 05:33

I\'m working on an app that may be seen in many countries in the world. There are not many countries that show hours, minutes and seconds with something other than : as a s

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-05 05:45

    I'm looking for a simple, single line to output a timeSpan in a culture-Aware manner.

    Then I think you're best off using the DateTime class to do the formatting for you:

    string display = new DateTime(timespan.Ticks).ToLongTimeString();
    

    Assuming that timespan holds a positive duration between 0 and 24 hours long.

提交回复
热议问题