C#库来解析人类可读的时间跨度 [英] C# Library to parse human readable time spans
问题描述
是否有存在,将解析人类可读的时间跨度为一个时间跨度.NET库?
Is there a library that exists that will parse human readable timespans into a .net TimeSpan?
我需要的东西,将解析字符串像
I need something that will parse strings like
30 days
1 week
5 hours
请问这样的事情存在吗?它可能不是太难自己写,但如果事情就在那里,这将是容易得多!
Does such a thing exist? Its probably not too hard to write myself, but if something is out there, it would be so much easier!
我目前并不需要像提前30天的功能, 3小时,5分钟,只是一个值,但它不能伤害!
I currently don't need functionality like "30 days, 3 hours, 5 minutes", just the one value, but it couldn't hurt!
推荐答案
我参加了一个裂缝在这个一段时间后,我与分析器扮演我也不知道他们,所以不要指望质量。但是你可以在这里得到的代码: http://timestamper.codeplex.com/
I took a crack at this sometime back, I was playing with parsers as I knew nothing about them so don't expect quality. But you can get the code here: http://timestamper.codeplex.com/
我还没有看它一段时间,但即时通讯相当确信它可以做所有你上面提到的事情
I havent looked at it for a while, but im pretty sure it can do all the things that you mentioned above.
编辑:
就指出,你想一个时间跨度对象返回,而不是一个日期和时间。该代码我提供将返回一个DateTime reletive到今天即
Just noted that you wanted a timespan object returned and not a date time. The code I provided will return a DateTime reletive to today i.e.
2日将是:DateTime.Now.AddDays(2);
"2 days" will be: DateTime.Now.AddDays(2);
至少我认为这是什么一样,可以非常肯定。如果是这种情况,你应该能够得到这两个日期时间之间的时间跨度。
At least I think this is what is did, can quite be sure. If this is the case, you should just be able to get the timespan between the two DateTimes.
这篇关于C#库来解析人类可读的时间跨度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!