文本框中的DateTime操作 [英] DateTime Operation in Textboxes

查看:63
本文介绍了文本框中的DateTime操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何使用DateTime在文本框上操作???。意味着

i有两个文本框,我希望,(textbox2 - textbox1)在C#windows窗体中以时间格式在textbox3中给出答案,基本上我我正在研究时间管理系统,有没有解决我问题的语法。

i我正在使用文本框和maskedtextbox ..

How can we Operate on textbox using DateTime???.means
i have two textboxes and i want,(textbox2 - textbox1) gives answer in textbox3 in Time Format in C# windows form,basically i am working on "Time Management System",Have there any Syntax that solve my problem.
i am using textbox and also maskedtextbox..

推荐答案

您必须将文本框的内容强制转换为DateTime。您可以使用静态方法 DateTime.Parse()执行此操作。

You must cast the content of your textbox to a DateTime. You can do this with the static method DateTime.Parse().
DateTime date1 = DateTime.Parse(textBox1.Text);
DateTime date2 = DateTime.Parse(textBox2.Text);
TimeSpan date3 = date2 - date1;
textBox3.Text = date3.ToString();





编辑:当我点击提交时,Abhinav已经提供了答案。



By the time I hit Submit, Abhinav had already provided an answer.

尝试类似

textBox3 =((TimeSpan)DateTime.Parse(textBox1).Subtract(DateTime.Parse,textBox2))。Days;


我建​​议使用DateTimePickers而不是TextBoxes。
I recommend using DateTimePickers rather than TextBoxes.


这篇关于文本框中的DateTime操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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