解析字符串时间跨度 [英] Parse string to TimeSpan

查看:115
本文介绍了解析字符串时间跨度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有XXH的一些字符串:YYM格式,其中xx是小时,yy是像分钟05H:30M。什么是这种类型为TimeSpan的字符串转换成一个优雅的方式?

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?

推荐答案

这似乎工作,虽然这是一个有点hackish的:

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());

这篇关于解析字符串时间跨度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆