时钟总和分钟与时间跨度

编程入门 行业动态 更新时间:2024-10-11 03:22:18
本文介绍了时钟总和分钟与时间跨度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有两个文本框, txt1.text =07:00'时钟 txt2.text =10 '分钟 i希望结果是07:10我想要使用时间跨度。 希望你能帮助我

解决方案

解析两个:

DateTime dt; int 分钟; if (DateTime.TryParse(txt1.Text, out dt)&&& span class =code-keyword> int .TryParse(txt2.Text, out 分钟)) { TimeSpan ts = new TimeSpan( 0 ,分钟, 0 ); dt = dt + ts; Console.WriteLine(dt.ToString( hh:mm)); }

我会执行以下操作: - 拆分你的txt1.text(在:处)并将2部分转换为整数 - 将其转换为日期 - 将txt2.text转换为整数 - 将此值添加为分钟日期 - 生成之前(myDate.addminutes(cint(txt2.text))

轮到我^ _ ^ CultureInfo provider = CultureInfo.InvariantCulture; string clockFormat = hh:mm; string clockStr = txt1.Text; string minutesStr = txt2.Text; double 分钟; DateTime时钟; TimeSpan时间; if (!DateTime.TryParseExact(clockStr,clockFormat,provider,DateTimeStyles.None) , o ut clock)) clock = new DateTime( 0 , 0 , 0 ); // DateTime很好,除非你在23:40加50分钟。获得额外的日子并不容易。我不知道你是否需要,但是: TimeSpan clockTime = clock.TimeOfDay; if ( double .TryParse(minutesStr, out 分钟))分钟= 0 。 0 ; time = TimeSpan.FromMinutes(分钟); // 这是数据时间方面。您可以使用TimeOfDay从午夜开始获取TimeSpan: DateTime totalTime = clock.Add(time); // 或者你可以使用clockTime获得整个TimeSpan,包括任何额外的天数 TimeSpan totalTimeSpan = clockTime.Add(time);

I have two textbox, txt1.text = "07:00" 'clock txt2.text ="10" ' minute i hope result to be 07:10 i want use timespan. hope you help me

解决方案

Parse the two:

DateTime dt; int minutes; if (DateTime.TryParse(txt1.Text, out dt) && int.TryParse(txt2.Text, out minutes)) { TimeSpan ts = new TimeSpan(0, minutes, 0); dt = dt + ts; Console.WriteLine(dt.ToString("hh:mm")); }

I would do the following : - split your txt1.text (at the ":") and cast the 2 parts into Integer - convert it into Date - cast txt2.text into integer - add this value as minutes to the Date - generated before (myDate.addminutes(cint(txt2.text))

My turn ^_^

CultureInfo provider = CultureInfo.InvariantCulture; string clockFormat = "hh:mm"; string clockStr = txt1.Text; string minutesStr = txt2.Text; double minutes; DateTime clock; TimeSpan time; if(!DateTime.TryParseExact(clockStr,clockFormat,provider,DateTimeStyles.None, out clock)) clock = new DateTime(0,0,0); //DateTime is fine unless you add 50 minutes to 23:40. It is not as easy to get the extra days. I don't know if you need to or not, but: TimeSpan clockTime = clock.TimeOfDay; if (double.TryParse(minutesStr, out minutes)) minutes = 0.0; time = TimeSpan.FromMinutes(minutes); //This is the datatime aspect. You can use TimeOfDay to get the TimeSpan since midnight: DateTime totalTime = clock.Add(time); //Or you can get the whole TimeSpan including any extra days using the clockTime TimeSpan totalTimeSpan = clockTime.Add(time);

更多推荐

时钟总和分钟与时间跨度

本文发布于:2023-11-27 14:19:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1638426.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:跨度   总和   时钟   时间

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!