469,572 Members | 1,191 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

convert a C++ CTime to a C# DateTime

Hello,

How can i convert a C++ CTime (4 bytes) into a C# DateTime ?
(my CTime is read in a file).

Thanks,
--
Chris
Nov 16 '05 #1
2 17751
dear Chris,

The Parse method of DateTime may handle this, take a try(remember to read
the CTime as a string first).

hope it helps.

"Chris" wrote:
Hello,

How can i convert a C++ CTime (4 bytes) into a C# DateTime ?
(my CTime is read in a file).

Thanks,
--
Chris

Nov 16 '05 #2

"Chris" <bo****@nowhere.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hello,

How can i convert a C++ CTime (4 bytes) into a C# DateTime ?
(my CTime is read in a file).


I beleive that CTime has the same storage representation as time_t, which is
a 64 bit integer representing the number of seconds since January 1, 1970
UDT. Marshall it as an Int64, and do the date arithmetic yourself.

Something like
static DateTime CTimeToDate(Int64 CTime)
{
TimeSpan span = TimeSpan.FromTicks(CTime*TimeSpan.TicksPerSecond);
DateTime t = new DateTime(1970,1,1).Add(span);
return TimeZone.CurrentTimeZone.ToLocalTime(t);
}

David
Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Vicki Carlsen | last post: by
2 posts views Thread by Thomas Lindroos | last post: by
5 posts views Thread by Fabio | last post: by
1 post views Thread by NareshN | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.