Thread: converting 64 bit time and date

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    99

    converting 64 bit time and date

    Hi, Ive used c++ in the past to convert unix time stamps but now I have a 64 bit time stamp to convert 'CB 6E 70 FE B9 C8 01 00' and im not sure how to go about this? is it a similar process to the unix way? Im a bit stuck

  2. #2
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Where did that 64-bit time-stamp come from, and which UNIX way are you referring to?

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    99
    my program basically examines a file which contains a 64 bit time stamp which I want to strip out of the file and display in a normal readable formatt. The time stamp spans from byte 2 to byte 10 of the file.

    below is how ive converted time stamps before
    Code:
    struct tm t = *localtime(&timestamp);
    	char buf[80];
    	if (strftime(buf, sizeof buf, "%a, %d %B %Y %H:%M:%S UTC", &t) == 0)
    	{
    		std::cerr << "Error calling strftime." << std::endl;
    	}
    	std::cout << buf << std::endl;

  4. #4
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    Again, where did that come from? Knowing what type of file you're looking at would greatly aid us. Right now, we have a sequence of 8 bytes, and some time-converting code that I'm assuming gives the wrong answer.

    • In what type of file you found these bytes, so we might look up format info.
    • Is this big endian? little endian?
    • What makes you think it's a timestamp, and do you know what date/time those bytes correspond to?
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  5. #5
    Registered User
    Join Date
    Apr 2008
    Posts
    99
    no probs,

    its a Windows 64 bit time stamps stored in little endian formatt which resides inside a link file(shortcut file). Its basically the created date for the link file and I would like to convert this to a readable format

  6. #6
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    In that case, this is probably what you want: FileTimeToSystemTime()

  7. #7
    Registered User
    Join Date
    Apr 2008
    Posts
    99
    thanks, Ive been having a look at this today wen i stuimbled across it earlier but if im honest I just dont know how to start it! I have my time stamp stored in my variable

    char modifiedTime[]

    I presume I somehow pass this to

    FileTimeToSystemTime()

    but I believe it need to be converted into some sort of time styructure for it to be correctly read?

    then to display the date you print it out using the wYear, wDay........so on;

  8. #8
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    This link should show you the usage of FileTimeToSystemTime().

    ssharish

  9. #9
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    You'd need to convert the timestamp string into a 64-bit int.
    Here you see that the FILETIME struct has two DWORD numbers for the low and high part of the 64-bit value, so take half the timestamp string and convert it to a DWORD and store it in the high part, then take the other half, convert it and store it in the low part...

  10. #10
    Registered User
    Join Date
    Apr 2008
    Posts
    99
    Hi Ive been having a look at that today and although i dont totally understand how to implement this totally I've had a go at the following code. It returns back one error so I'm hoping I mite be close, can you guys see where i may have gone wrong?


    Code:
    char createdTime[] = {_ct1,_ct2,_ct3,_ct4,_ct5,_ct6,_ct7,_ct8,'\0'};  This contains my timestamp  information stored from the file im processing
    
    
     
    
    DATE dt;
    
           memcpy(&dt, createdTime, sizeof(DATE));
    
           SYSTEMTIME stime;
           FileTimeToSystemTime( dt, &stime ); // convert to structure
        
           cout << stime.wMonth << "/" << stime.wDay << "/ " << stime.wYear << "     Time:"  <<           stime.wHour<<":"<< stime.wMinute << ":"<<stime.wSecond  <<"\n";
         
    
    cout << "The created time is   "<< createdTime << " "<< endl;

  11. #11
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    It would help if you told us the error you're getting, but I'm guessing it's because you're passing a DATE parameter to FileTimeToSystemTime() instead of the FILETIME parameter that it's expecting.

  12. #12
    Registered User
    Join Date
    Apr 2008
    Posts
    99
    changing it to FILETIME i get the errors

    cannot convert _FILETIME to const _FILETIME *

    and

    type mismatch in parameter lpfiletime

  13. #13
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >cannot convert _FILETIME to const _FILETIME *
    Did you try:
    Code:
           FILETIME filetime;
    
           memcpy(&filetime, createdTime, sizeof(DATE));
           FileTimeToSystemTime( &filetime, &stime ); // convert to structure

  14. #14
    Registered User
    Join Date
    Apr 2008
    Posts
    99
    sorry to be a pain but I'm starting to get lost off as to what im doing now. I have the following code



    Code:
    
    char createdTime[] = {_ct1,_ct2,_ct3,_ct4,_ct5,_ct6,_ct7,_ct8,'\0'};   //my time stamp
     
    /***************DO I NEED BOTH OF THESE?***************/
           
              DATE dt;
    
              FILETIME filetime;
    
    /*******************************************************/
       
            memcpy(&filetime, createdTime, sizeof(DATE));
    
    
      
      //THE BELOW CODE IS WHERE I START TO GET THE ERRORS
    
      FileTimeToSystemTime( &filetime, &stime ); // convert to structure
    
    
     cout << stime.wMonth << "/" << stime.wDay << "/ " << stime.wYear << "     Time:"  << stime.wHour<<":"<< stime.wMinute << ":"<<stime.wSecond  <<"\n";


    The errors i now get is "pointer to overloaded function stime" and "type mismatch in lpsystemtime". I'm a little confused as to where stime comes from here


    thank you for your patients

  15. #15
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >I'm a little confused as to where stime comes from here
    You had it defined a couple of posts ago. Check this post from above.
    Quote Originally Posted by pastitprogram View Post
    Hi Ive been having a look at that today and although i dont totally understand how to implement this totally I've had a go at the following code. It returns back one error so I'm hoping I mite be close, can you guys see where i may have gone wrong?


    Code:
    char createdTime[] = {_ct1,_ct2,_ct3,_ct4,_ct5,_ct6,_ct7,_ct8,'\0'};  This contains my timestamp  information stored from the file im processing
    
    
     
    
    DATE dt;
    
           memcpy(&dt, createdTime, sizeof(DATE));
    
           SYSTEMTIME stime;
           FileTimeToSystemTime( dt, &stime ); // convert to structure
        
           cout << stime.wMonth << "/" << stime.wDay << "/ " << stime.wYear << "     Time:"  <<           stime.wHour<<":"<< stime.wMinute << ":"<<stime.wSecond  <<"\n";
         
    
    cout << "The created time is   "<< createdTime << " "<< endl;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Advancing day by day until it matches a second date
    By nhubred in forum C++ Programming
    Replies: 1
    Last Post: 05-30-2009, 08:55 AM
  2. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  3. How to get and set windows time and date
    By huwan in forum Windows Programming
    Replies: 18
    Last Post: 05-13-2008, 10:33 AM
  4. Sending an email in C program
    By Moony in forum C Programming
    Replies: 28
    Last Post: 10-19-2006, 10:42 AM