如何在时间跨度进行划分 [英] how to perform division in timespan

查看:155
本文介绍了如何在时间跨度进行划分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在时间跨度值,让我们说: TSP1 = 2每小时5分钟的路程。
我有一个包含像一个值的另一时间跨度变量: TSP2 = 0小时2分

I have a value in TimeSpan, let's say: tsp1 = 2 hour 5 minutes. I have another TimeSpan variable which contains a value like: tsp2 = 0 hours 2 minutes

请告诉我,我该怎么划分 TSP1 TSP2 使我可以得到的时间 TSP2 划分的确切数量为 TSP1 ,什么剩余部分。

Please tell me how I can divide tsp1 by tsp2 so that I can get the exact number of times tsp2 divides into tsp1 and what the remainder is.

我使用Visual Studio 2008。

I am using Visual Studio 2008.

感谢。

推荐答案

最简单的方法可能只是采取蜱它们的长度,并划分这些。例如:

The simplest approach is probably just to take their lengths in ticks, and divide those. For example:

long ticks1 = tsp1.Ticks;
long ticks2 = tsp2.Ticks;

long remainder;
long count = Math.DivRem(ticks1, ticks2, out remainder);

TimeSpan remainderSpan = TimeSpan.FromTicks(remainder);

Console.WriteLine("tsp1/tsp2 = {0}, remainder {1}", count, remainderSpan);

这篇关于如何在时间跨度进行划分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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