Convert time_t to System::DateTime ???

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 ???
 
M

Mark Salsbery [MVP]

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
 
P

PeteOlcott

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;
}
 
P

PeteOlcott

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;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top