Convert time_t to System::DateTime ???

  • Thread starter Thread starter PeteOlcott
  • Start date Start date
P

PeteOlcott

I need to convert time_t to System::DateTime. All of the examples that
I found are either in C# or in the obsolete managed C++ syntax. What
is the current syntax for converting a (probably 64 bit) time_t value
to System::DateTime ???
 
PeteOlcott said:
I need to convert time_t to System::DateTime. All of the examples that
I found are either in C# or in the obsolete managed C++ syntax. What
is the current syntax for converting a (probably 64 bit) time_t value
to System::DateTime ???


time_t t = ...;
long long filetime = t * 10000000LL + 116444736000000000LL;
DateTime datetime = DateTime::FromFileTimeUtc(filetime);
Console::WriteLine(datetime.ToString());



Mark
 
Here's my source, BTW:

Converting a time_t Value to a File Timehttp://msdn.microsoft.com/en-us/library/ms724228(VS.85).aspx

Mark

Here is the answer that I derived:

System::DateTime time_tToSystemDateTime(time_t tt)
{
tm* timeptr = gmtime(&tt);
DateTime sdt(timeptr->tm_year + 1900, timeptr->tm_mon + 1, timeptr-
tm_mday, timeptr->tm_hour, timeptr->tm_min, timeptr->tm_sec);
return sdt;
}
 
Here is the answer that I derived:

System::DateTime time_tToSystemDateTime(time_t tt)
{
  tm* timeptr = gmtime(&tt);
  DateTime sdt(timeptr->tm_year + 1900, timeptr->tm_mon + 1, timeptr-



  return sdt;
}- Hide quoted text -

- Show quoted text -

Here it is again, (Hopefully with better formatting)

System::DateTime time_tToSystemDateTime(time_t tt)
{
tm* timeptr = gmtime(&tt);
DateTime sdt(timeptr->tm_year + 1900,
timeptr->tm_mon + 1,
timeptr->tm_mday,
timeptr->tm_hour,
timeptr->tm_min,
timeptr->tm_sec);
return sdt;
}
 
Back
Top