添加的总和小时,像13或30 + 00:00:20 = 13:30:​​20,但怎么样? [英] Add or Sum of hours like 13:30+00:00:20=13:30:20 but how?

查看:130
本文介绍了添加的总和小时,像13或30 + 00:00:20 = 13:30:​​20,但怎么样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想补充的日期时间值秒(00:00:02)或分钟(00:00:20)(可存储字符串类型),但怎么样?例如:

I want to add seconds (00:00:02) or minutes (00:00:20) on datetime value (may be stored string type) but how? Examples:

13:30+02:02:02= 15:32:02 ,
13:30+00:00:01= 13:30:01 ,
13:30+00:01:00=13:31:00 or 13:30 (not important) 

您能帮我吗?我又需要冷静的算法:)谢谢...

Can you help me? I need your cool algorithm :) Thanks again...

推荐答案

如果您选择使用的时间跨度,要注意对天部分:

If you choose to use the TimeSpan, be aware about the Days part:

TimeSpan t1 = TimeSpan.Parse("23:30");
TimeSpan t2 = TimeSpan.Parse("00:40:00");
TimeSpan t3 = t1.Add(t2);
Console.WriteLine(t3); // 1.00:10:00

使用日期时间:

DateTime d1 = DateTime.Parse("23:30");
DateTime d2 = DateTime.Parse("00:40:00");
DateTime d3 = d1.Add(d2.TimeOfDay); 
Console.WriteLine(d3.TimeOfDay); // 00:10:00

这篇关于添加的总和小时,像13或30 + 00:00:20 = 13:30:​​20,但怎么样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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