.NET Framework Developer Center >
.NET Development Forums
>
Common Language Runtime
>
How to convert _timeb time into C# DateTime object
How to convert _timeb time into C# DateTime object
- My program references a datafile that has record times listed as timebuffer.time in C++. This is the code that sets the time from the C++ side:
struct _timeb timebuffer;
unsigned int Time;
_ftime (&timebuffer);
DX_data.Time = (unsigned int)timebuffer.time;
i would like to read that in on my side (C#) and output it my appropriate format. Could someone help me out with this?
THanks,
Answers
- You can do this by creating a timespan and adding it to the reference time. It sounds like you're doing this in C++, in which case, it'd be:
// using namespace System;
struct _timeb timebuffer;
_ftime(&timebuffer);
TimeSpan ts = TimeSpan(0,0,0, timebuffer.time, timebuffer.millitm);
DateTime refTime = DateTime(1970,1,1);
DateTime finalTime = refTime + ts;
Reed Copsey, Jr. - http://reedcopsey.com- Proposed As Answer byReed Copsey, Jr. Monday, November 02, 2009 7:51 PM
- Marked As Answer byeryangMSFT, ModeratorTuesday, November 10, 2009 9:17 AM
- Marked As Answer byeryangMSFT, ModeratorMonday, November 09, 2009 7:24 AM
- Unmarked As Answer byeryangMSFT, ModeratorMonday, November 09, 2009 7:25 AM
All Replies
- You can do this by creating a timespan and adding it to the reference time. It sounds like you're doing this in C++, in which case, it'd be:
// using namespace System;
struct _timeb timebuffer;
_ftime(&timebuffer);
TimeSpan ts = TimeSpan(0,0,0, timebuffer.time, timebuffer.millitm);
DateTime refTime = DateTime(1970,1,1);
DateTime finalTime = refTime + ts;
Reed Copsey, Jr. - http://reedcopsey.com- Proposed As Answer byReed Copsey, Jr. Monday, November 02, 2009 7:51 PM
- Marked As Answer byeryangMSFT, ModeratorTuesday, November 10, 2009 9:17 AM
- Marked As Answer byeryangMSFT, ModeratorMonday, November 09, 2009 7:24 AM
- Unmarked As Answer byeryangMSFT, ModeratorMonday, November 09, 2009 7:25 AM
- I'm doing it in C#. I tried it in the C# code, and that is what i am looking for. Thanks!
- Hi,
We need a c++ method that returns the timebuffer.time , so that we can get the time value in C# code.
If you already have, do you mind post the method signature?
Thanks,
Eric
Please remember to mark helpful replies as answers and unmark them if they provide no help. - My previous answer showed you C++ code to get timebuffer.time. The call is _ftime:
struct _timeb timebuffer;
_ftime(&timebuffer);
time_t time = timebuffer.time;
That's all there is to it.
Reed Copsey, Jr. - http://reedcopsey.com- Proposed As Answer byReed Copsey, Jr. Monday, November 09, 2009 5:58 PM


