在文本框中显示日期和时间 [英] show date and time in textBoxes

查看:185
本文介绍了在文本框中显示日期和时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请获取有关从系统获取日期和时间以在Windows窗体应用程序的框中显示的帮助.
我想在textBox1中显示日期,并在textBox2中显示时间.

please help about get date and time from system to show in box in the windows form application .
i want to show date in textBox1 and show time in textBox2.

推荐答案

Datetime d = new DateTime();
d = DateTime.Now;

TextBox1.Text = d.ToString("dd.MM.yyyy");
TextBox2.Text = d.ToString("HH:mm:ss");



Google会为您提供相同的结果,如果您自己尝试一下自己的想法,那将是很好的选择,而不是发布这个非疑问的问题,我必须为您完成工作吗?)



Google would give you the same result, and It would be nice if you tried somethin gyourself, instead of posting this non question, were I have to do the work for you ;)


为什么显示它在文本框中?文本框也可以输入数据,但是如果用户通过在文本框中键入时间来输入时间,就很容易出错,并且您还需要保持某种特定的格式或输入,请告知用户确切使用了什么格式.所以,这不是最好的主意.

最好使用System.Windows.Forms.DateTimePicker:
http://msdn.microsoft.com/zh-cn/library/system.windows.forms.datetimepicker%28v = vs.100%29.aspx [
Why showing it in the text box? Text box is designed to input of data as well, but if a user enters time by typing in a text box, it''s too easy to make a mistake, and you also need to maintain some particular format or input, inform the user what exactly format is used. So, this is not the best idea.

It''s much better to use System.Windows.Forms.DateTimePicker:
http://msdn.microsoft.com/en-us/library/system.windows.forms.datetimepicker%28v=vs.100%29.aspx[^].

—SA


仅使用两行代码..
Use just 2lines of code..
textbox2.Text = DateTime.Now.ToString("hh:mm:ss tt");
textbox1.Text = DateTime.Now.ToString("dd MMMM,yyyy");


这篇关于在文本框中显示日期和时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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