C#时差计算 [英] C# Time difference calculation

查看:92
本文介绍了C#时差计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我必须编写一个函数来计算同一个用户输入的两个任务之间的时差,这个任务将在Excel工作表中显示。如何写这个功能?



请帮帮我。



先谢谢。

Hi All,

I have to write a function for calculating the time difference between two tasks entered by the same user which is to be displayed in the excel sheet.How to write that function?

please help me.

Thanks in Advance.

推荐答案

你好,



尝试使用TimeSpan或搜索TimeSpan示例。



谢谢

sanjeev
hello,

try to use use TimeSpan or search TimeSpan example.

thanks
sanjeev


尝试

Try
DateTime dt1 = DateTime.ParseExact(time1, "HH:mm:ss", new DateTimeFormatInfo());
DateTime dt2 = DateTime.ParseExact(time2, "HH:mm:ss", new DateTimeFormatInfo());
TimeSpan ts = dt1.Subtract(dt2);


一个改进:在Abhinav的解决方案中,写下最后一行更好这个:



One improvement: in the solution by Abhinav, it's much better to write the last line like this:

TimeSpan ts = dt1 - dt2;
//yes, subtraction operator "-" is defined, of course





-SA


这篇关于C#时差计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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