Click here to Skip to main content
15,915,160 members
Home / Discussions / C#
   

C#

 
GeneralRe: Casting again - from parent to child Pin
Grep30-Mar-04 9:59
Grep30-Mar-04 9:59 
GeneralRe: Casting again - from parent to child Pin
Heath Stewart30-Mar-04 10:08
protectorHeath Stewart30-Mar-04 10:08 
QuestionIs this a pointer operation ? Pin
Andres Coder30-Mar-04 8:28
Andres Coder30-Mar-04 8:28 
AnswerRe: Is this a pointer operation ? Pin
leppie30-Mar-04 8:50
leppie30-Mar-04 8:50 
AnswerRe: Is this a pointer operation ? Pin
Andy Wieberneit30-Mar-04 11:09
Andy Wieberneit30-Mar-04 11:09 
AnswerRe: Is this a pointer operation ? Pin
Bryan White31-Mar-04 9:01
Bryan White31-Mar-04 9:01 
GeneralC# time to C++ time_t Pin
goodpilot30-Mar-04 8:22
goodpilot30-Mar-04 8:22 
GeneralRe: C# time to C++ time_t Pin
Heath Stewart30-Mar-04 9:31
protectorHeath Stewart30-Mar-04 9:31 
Since time_t is just an unsigned 32-bit integer, you can use uint (alias for UInt32), but I recommend you don't depending on how you use it because unsigned types in .NET are not CLS-compliant (i.e., less portable code). Whenever you need to pass it to unmanaged code or get it back, you can use the MarshalAsAttribute with UnmanagedType.U4. For instance, 0xffff is -1 for an Int32 while it is 65535 for a UInt64. The value is still the same, it's just how it's interpreted. The marshaling I mentioned above will take care of this.

The biggest hurdle has to do with the epoch (start time) of each. time_t is the number of seconds that have ellapsed since 12:00 midnight, 1-1-1970. A DateTime in .NET represents the number of ticks (100 nanoseconds) since 12:00 midnight, 1-1-0001 AD. This definitely becomes a hurdle as I'm sure you can see.

One easy way to convert between the two is to create a DateTime that starts at the epoch of a time_t, and then add the number of seconds represented by time_t:
DateTime dt = DateTime.Parse("1970-01-01T00:00:00");
dt.AddSeconds(time_t); // From wherever it comes
If you do this a lot, you might consider storing the return from DateTime.Parse as a read-only field of your class (the readonly keyword lets the field be set in the static or instance constructor and can never be set again, which is good since you can't use a const for a non-constant value like this).

 

Microsoft MVP, Visual C#
My Articles
GeneralRe: C# time to C++ time_t Pin
goodpilot30-Mar-04 10:19
goodpilot30-Mar-04 10:19 
GeneralRe: C# time to C++ time_t Pin
Bryan White31-Mar-04 9:11
Bryan White31-Mar-04 9:11 
GeneralRe: C# time to C++ time_t Pin
Heath Stewart31-Mar-04 9:17
protectorHeath Stewart31-Mar-04 9:17 
GeneralWriting and closing files Pin
Member 70426330-Mar-04 7:32
Member 70426330-Mar-04 7:32 
GeneralRe: Writing and closing files Pin
leppie30-Mar-04 7:46
leppie30-Mar-04 7:46 
GeneralRe: Writing and closing files Pin
Member 70426330-Mar-04 7:53
Member 70426330-Mar-04 7:53 
GeneralRe: Writing and closing files Pin
Heath Stewart30-Mar-04 8:51
protectorHeath Stewart30-Mar-04 8:51 
GeneralMP3 Streaming sdk Pin
refahn30-Mar-04 7:32
refahn30-Mar-04 7:32 
GeneralJoint Collection Project Pin
Jonathan de Halleux30-Mar-04 7:13
Jonathan de Halleux30-Mar-04 7:13 
GeneralRe: Joint Collection Project Pin
leppie30-Mar-04 7:42
leppie30-Mar-04 7:42 
GeneralRe: Joint Collection Project Pin
Jonathan de Halleux30-Mar-04 7:48
Jonathan de Halleux30-Mar-04 7:48 
GeneralRe: Joint Collection Project Pin
leppie30-Mar-04 7:50
leppie30-Mar-04 7:50 
GeneralRe: Joint Collection Project Pin
Jonathan de Halleux30-Mar-04 7:54
Jonathan de Halleux30-Mar-04 7:54 
GeneralRe: Joint Collection Project Pin
Nemanja Trifunovic30-Mar-04 7:55
Nemanja Trifunovic30-Mar-04 7:55 
GeneralRe: Joint Collection Project Pin
Jonathan de Halleux30-Mar-04 8:00
Jonathan de Halleux30-Mar-04 8:00 
GeneralRe: Joint Collection Project Pin
Heath Stewart30-Mar-04 8:48
protectorHeath Stewart30-Mar-04 8:48 
GeneralRe: Joint Collection Project Pin
Jonathan de Halleux30-Mar-04 8:52
Jonathan de Halleux30-Mar-04 8:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.