Parse string to TimeSpan

前端 未结 5 1144
北海茫月
北海茫月 2020-12-17 08:11

I have some strings of xxh:yym format where xx is hours and yy is minutes like \"05h:30m\". What is an elegant way to convert a string of this type to TimeSpan?

5条回答
  •  無奈伤痛
    2020-12-17 08:56

    This seems to work, though it is a bit hackish:

    TimeSpan span;
    
    
    if (TimeSpan.TryParse("05h:30m".Replace("m","").Replace("h",""), out span))
                MessageBox.Show(span.ToString());
    

提交回复
热议问题