Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. cTime

cTime

Scheduled Pinned Locked Moved C#
c++
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    exhaulted
    wrote on last edited by
    #1

    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 - Today 10771200010000000 - 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

    L 1 Reply Last reply
    0
    • E exhaulted

      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 - Today 10771200010000000 - 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

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      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 - Screenshots

      E 1 Reply Last reply
      0
      • L leppie

        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 - Screenshots

        E Offline
        E Offline
        exhaulted
        wrote on last edited by
        #3

        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

        D 1 Reply Last reply
        0
        • E exhaulted

          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

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          You might want to take a look at this[^]. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

          E 1 Reply Last reply
          0
          • D Dave Kreskowiak

            You might want to take a look at this[^]. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

            E Offline
            E Offline
            exhaulted
            wrote on last edited by
            #5

            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

            D 1 Reply Last reply
            0
            • E exhaulted

              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

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              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

              E 1 Reply Last reply
              0
              • D Dave Kreskowiak

                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

                E Offline
                E Offline
                exhaulted
                wrote on last edited by
                #7

                OK, so the number im reading in was stored based on seconds since 1970 but the Dot Net framework's times are based on 100 nanoseconds since 0001?? Kev

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups