cTime
-
Hi all. I'm trying to read in the date and time from a binary file that was created using mfc. The cTime class was used to create the time stamp. I'm using a TimeSpan object and a DateTime object in order to get the date and time that was saved in the binary file. i.e.
public Count(BinaryReader read)
{
TimeSpan span = TimeSpan.FromSeconds(read.ReadUInt32());
TimeStamp = new DateTime(span.Ticks);
CountNumber = read.ReadUInt32();
}The date and time returned ends up coming out as
18/02/0035 16:00:01
which is obviously incorrect as this is old data not future data :-) I looked at the number of ticks returned in span.Ticks compared to the current number of ticks (at roughly 15:22 today)632460649505030970
- Today10771200010000000
- Returned from the file. As you can see there is a big difference and im pretty sure this data is only a year old at the most. If anyone knows what i'm doing wrong it would be greatly appreciated. Cheers Kev -
Hi all. I'm trying to read in the date and time from a binary file that was created using mfc. The cTime class was used to create the time stamp. I'm using a TimeSpan object and a DateTime object in order to get the date and time that was saved in the binary file. i.e.
public Count(BinaryReader read)
{
TimeSpan span = TimeSpan.FromSeconds(read.ReadUInt32());
TimeStamp = new DateTime(span.Ticks);
CountNumber = read.ReadUInt32();
}The date and time returned ends up coming out as
18/02/0035 16:00:01
which is obviously incorrect as this is old data not future data :-) I looked at the number of ticks returned in span.Ticks compared to the current number of ticks (at roughly 15:22 today)632460649505030970
- Today10771200010000000
- Returned from the file. As you can see there is a big difference and im pretty sure this data is only a year old at the most. If anyone knows what i'm doing wrong it would be greatly appreciated. Cheers Kevi think ticks start at
1970/01/01 00:00:00
in a PE file stamp. And what i can see, the result will be correct then :) (2005/02/18) xacc-ide 0.0.15 now with C#, MSIL, C, XML, ASP.NET, Nemerle, MyXaml and HLSL coloring - Screenshots -
i think ticks start at
1970/01/01 00:00:00
in a PE file stamp. And what i can see, the result will be correct then :) (2005/02/18) xacc-ide 0.0.15 now with C#, MSIL, C, XML, ASP.NET, Nemerle, MyXaml and HLSL coloring - ScreenshotsI get the correct date returned when i create a DateTime object with the "Current" number of ticks
632460649505030970
but when i create one with the number of ticks created using the reader i'm getting the date mentioned above,18/02/0035 16:00:01
which is very wrong. For some reason the number of ticks that i get returned from span.Ticks must be wrong. Any ideas anyone?? Kev -
I get the correct date returned when i create a DateTime object with the "Current" number of ticks
632460649505030970
but when i create one with the number of ticks created using the reader i'm getting the date mentioned above,18/02/0035 16:00:01
which is very wrong. For some reason the number of ticks that i get returned from span.Ticks must be wrong. Any ideas anyone?? Kev -
A good article, but it seems to cover everything except what i want. The mfc class being used to store the time is cTime and the article mentions that this class provides an overload for the >> and << operators which are being used to store the time. The article just doesn't go into any details about how they are overloaded. The time is being saved using the >> (or <<, cant remember :-P) operator and i need to read it into a C# class in such a way as i can get at the date and time. I thought, as did leppy from his comments, that what i did would work but it doesn't so i assume that cTime stores the dateTime in a different format. If anyone knows how to do this it would be great. I dont need to know why it doesn't work i just need a way to read the cTime data, that has been stored using the >> operator, into a DateTime class in C#. Cheers Kev
-
A good article, but it seems to cover everything except what i want. The mfc class being used to store the time is cTime and the article mentions that this class provides an overload for the >> and << operators which are being used to store the time. The article just doesn't go into any details about how they are overloaded. The time is being saved using the >> (or <<, cant remember :-P) operator and i need to read it into a C# class in such a way as i can get at the date and time. I thought, as did leppy from his comments, that what i did would work but it doesn't so i assume that cTime stores the dateTime in a different format. If anyone knows how to do this it would be great. I dont need to know why it doesn't work i just need a way to read the cTime data, that has been stored using the >> operator, into a DateTime class in C#. Cheers Kev
The point is that cTime stored the numebr of seconds since Jan 1, 1970 12:00am and the .NET Framework epoch is Jan 1, 0001 12:00am and stores the number of 100 nanosecond intervals since then. You'll have to do a little bit of math to convert the number of seconds to the number of ticks, then use that to create a DateTime object out of the result. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
The point is that cTime stored the numebr of seconds since Jan 1, 1970 12:00am and the .NET Framework epoch is Jan 1, 0001 12:00am and stores the number of 100 nanosecond intervals since then. You'll have to do a little bit of math to convert the number of seconds to the number of ticks, then use that to create a DateTime object out of the result. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome