如何在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.