Connecting Tech Pros Worldwide Forums | Help | Site Map

Convert time_t to System::DateTime ???

PeteOlcott
Guest
 
Posts: n/a
#1: Sep 22 '08
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 ???

Mark Salsbery [MVP]
Guest
 
Posts: n/a
#2: Sep 22 '08

re: Convert time_t to System::DateTime ???



"PeteOlcott" <PeteOlcott@gmail.comwrote in message
news:3e1d1cb6-371e-4f86-bb5f-ba58ede93b9d@m3g2000hsc.googlegroups.com...
Quote:
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

--
Mark Salsbery
Microsoft MVP - Visual C++


Mark Salsbery [MVP]
Guest
 
Posts: n/a
#3: Sep 22 '08

re: Convert time_t to System::DateTime ???


Here's my source, BTW:

Converting a time_t Value to a File Time
http://msdn.microsoft.com/en-us/libr...28(VS.85).aspx


Mark

--
Mark Salsbery
Microsoft MVP - Visual C++

PeteOlcott
Guest
 
Posts: n/a
#4: Sep 23 '08

re: Convert time_t to System::DateTime ???


On Sep 22, 5:45*pm, "Mark Salsbery [MVP]"
<MarkSalsbery[MVP]@newsgroup.nospamwrote:
Quote:
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
>
--
Mark Salsbery
Microsoft MVP - Visual C++
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-
Quote:
>tm_mday, timeptr->tm_hour, timeptr->tm_min, timeptr->tm_sec);
return sdt;
}

PeteOlcott
Guest
 
Posts: n/a
#5: Sep 23 '08

re: Convert time_t to System::DateTime ???


On Sep 22, 7:06*pm, PeteOlcott <PeteOlc...@gmail.comwrote:
Quote:
On Sep 22, 5:45*pm, "Mark Salsbery [MVP]"
>
<MarkSalsbery[MVP]@newsgroup.nospamwrote:
Quote:
Here's my source, BTW:
>
Quote:
Converting a time_t Value to a File Timehttp://msdn.microsoft.com/en-us/library/ms724228(VS.85).aspx
>
Quote:
Mark
>
Quote:
--
Mark Salsbery
Microsoft MVP - Visual C++
>
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-
>
>
>
Quote:
tm_mday, timeptr->tm_hour, timeptr->tm_min, timeptr->tm_sec);
* 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;
}
Closed Thread