convert a C++ CTime to a C# DateTime

  • Thread starter Thread starter Chris
  • Start date Start date
C

Chris

Hello,

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

Thanks,
 
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 said:
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
 
Back
Top