Datetime 如何将struct tm转换为c++/cli

Datetime 如何将struct tm转换为c++/cli,datetime,time,c++-cli,Datetime,Time,C++ Cli,我在c++/CLI中有一个变量,它将时间作为struct tm保存。我需要将其转换为托管日期时间。我该怎么做 struct tm t=GetTime(); DateTime time= ConvertToDateTime(t); 在上面的代码中,如何实现转换?一种方法是: struct tm t = GetTime(); // not sure of syntax here, calling the constructor from C++, // but I think you get

我在c++/CLI中有一个变量,它将时间作为struct tm保存。我需要将其转换为托管日期时间。我该怎么做

 struct tm t=GetTime();
 DateTime time= ConvertToDateTime(t);
在上面的代码中,如何实现转换?

一种方法是:

struct tm t = GetTime();
// not sure of syntax here, calling the constructor from C++,
// but I think you get the idea.
DateTime time = DateTime(t.tm_year+1900, t.tm_mon+1, t.tm_day, t.tm_hour, t.tm_min, t.tm_sec);

对种类也很重要,因为它取决于如何获得tm,所以对tm来说是不明确的。