将TimeSpan大于23:59:59划分为int值 [英] dividing a TimeSpan Greater Than 23:59:59 to an int value

查看:69
本文介绍了将TimeSpan大于23:59:59划分为int值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我该怎么做? :(我希望TS的格式为00:00:00

How can I do this? :( I want TS be in this format "00:00:00"

TimeSpan TS =TimeSpan.Parse("140:43") /30;

推荐答案

试试这个:

Try this:
string input = "140:43";
string[] parts = input.Split(':');
int hours = int.Parse(parts[0]);
int minutes = int.Parse(parts[1]);
int seconds;
if (parts.Length < 3)
{
    seconds = 0;
}
else
{
    seconds = int.Parse(parts[2]);
}
TimeSpan TS = new TimeSpan(hours, minutes, seconds);
TimeSpan resultAfterDivision = new TimeSpan(TS.Ticks / 30);



首先,您需要拆分给定的字符串。第一部分是小时数,第二部分是分钟数。如果没有给出第三部分,则秒数为0.否则,秒数是输入的第三部分。

然后,分割 TimeSpan ,你需要划分它的滴答数。


First, you need to split the given string. The first part is the number of hours and the second part the number of minutes. If no third part is given, the number of seconds is 0. Otherwise, the number of seconds is the third part of the input.
Then, to divide the TimeSpan, you need to divide its number of ticks.


这篇关于将TimeSpan大于23:59:59划分为int值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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