469,332 Members | 6,649 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,332 developers. It's quick & easy.

Convert time_t to System::DateTime ???

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 ???
Sep 22 '08 #1
4 5342

"PeteOlcott" <Pe********@gmail.comwrote in message
news:3e**********************************@m3g2000h sc.googlegroups.com...
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++
Sep 22 '08 #2
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++

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

Sep 23 '08 #4
On Sep 22, 7:06*pm, PeteOlcott <PeteOlc...@gmail.comwrote:
On Sep 22, 5:45*pm, "Mark Salsbery [MVP]"

<MarkSalsbery[MVP]@newsgroup.nospamwrote:
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-
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;
}
Sep 23 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Abdolhosein Vakilzadeh Ebrahimi | last post: by
10 posts views Thread by Philip Wagenaar | last post: by
2 posts views Thread by ziggislaw | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.