如何在C#中显示当前日期和时间并将其打印在文本框中? [英] How will Show the current date and time in C# and print it in a textbox?
本文介绍了如何在C#中显示当前日期和时间并将其打印在文本框中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在C#中显示当前日期和时间并将其打印在文本框中?
How will Show the current date and time in C# and print it in a textbox?
推荐答案
DateTime saveNow = DateTime.Now;
Console.WriteLine(saveNow);
要获取当前日期和时间:
To get the current date and time:
DateTime now = DateTime.Now;
然后,您可以将其格式化为您喜欢的内容-参见此处:格式化显示的DateTime-格式字符串说明 [ ^ ]
之后,这取决于您-我们不知道您的环境是什么,因此我们无法帮助您将格式化的文本放在任何地方!
You can then format it to your hearts content - see here: Formatting a DateTime for display - format string description[^]
After that, it''s up to you - we have no idea what your environment is, so we can''t help you put formatted text anywhere!
1)您可以使用DateTime C#中的类:
DateTime.Today.ToString("dd/MM/yyyy");这将为您提供"08/05/2012"
2)或者您可以将JavaScript用作:
var dateTime = new Date();
var day = dateTime.getDay();
var month = dateTime.getMonth();
var year = dateTime.getYear();
var displayString =天+"/" +月+"/" +年;
应用此功能,这将对您有所帮助.
1)You can use DateTime class in C#:
DateTime.Today.ToString("dd/MM/yyyy"); This will give you "08/05/2012"
2) Or you can use JavaScript as :
var dateTime = new Date();
var day = dateTime.getDay();
var month = dateTime.getMonth();
var year = dateTime.getYear();
var displayString = day + "/" + month + "/" + year;
apply this, This will be helpful to you.
这篇关于如何在C#中显示当前日期和时间并将其打印在文本框中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文