单击按钮时获取系统日期和时间作为字符串 - VC++ Windows 表单

Get system date and time as string when a button is clicked - VC++ Windows Forms

我正在开发 windows 表单应用程序并使用 c++,而不是 c#。我的表单中有一个按钮。单击此按钮时,必须获取系统日期和时间并将值分配给字符串 YearMonthDay小时分钟。我怎样才能做到这一点?我应该在按钮的点击事件处理程序中写什么?

注意:我是新手

您可以使用 System.DateTime.Now 属性。你想要的都有。

也许你的意思是:

String^ Year = System::DateTime::Now.Year.ToString();
String^ Month = System::DateTime::Now.Month.ToString();
String^ Day = System::DateTime::Now.Day.ToString();
String^ Hour = System::DateTime::Now.Hour.ToString();
String^ Minute = System::DateTime::Now.Minute.ToString();

小时值以 24 小时制表示。