GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 01-Jul-2008, 11:07
tootypegs tootypegs is offline
Junior Member
 
Join Date: Nov 2007
Posts: 32
tootypegs has a little shameless behaviour in the past

Convert my 64 bit Windows time stamp


hi I am trying to convert my 64 bit windows time stamp so that the date and time can be viewed by the user. I have the following code but it gives me a jumbled up date, not the one i was expecting, can anyone see a reason for this?

CPP / C++ / C Code:


char createdTime[] = {_ct1,_ct2,_ct3,_ct4,_ct5,_ct6,_ct7,_ct8};

 
     SYSTEMTIME stime ;
     FILETIME filetime;

     memcpy(&filetime, createdTime, sizeof(FILETIME));

     
     FileTimeToSystemTime( &filetime, &stime );  // convert to structure



    cout<< "This is the created date ";
cout << stime.wMonth << "/" << stime.wDay << "/ " << stime.wYear << "     Time:"  <<           stime.wHour<<":"<< stime.wMinute << ":"<<stime.wSecond  

<<"\n";
    




thankyou
Last edited by admin : 01-Jul-2008 at 11:56. Reason: Please insert your example C/C++ codes between [CPP] and [/CPP] tags
  #2  
Old 01-Jul-2008, 13:03
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,218
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: Convert my 64 bit Windows time stamp


Quote:
Originally Posted by tootypegs
t gives me a jumbled up date, not the one i was expecting,

I hate to ask silly questions, but:

1. What, exactly were you expecting (and what exactly did you get)?
2. What are the contents of your "createdTime" array?
3. Did you get the values for createtTIme from GetFileTime() or what? (And if you got values from GetFileTime(), why did you copy them into an array of chars?)

Try the following command-line program:
CPP / C++ / C Code:
//
//testfiletime.cpp
//
#include <iostream>
#include <iomanip>
#include <windows.h>

using namespace std;

int main(int argc, char **argv)
{
    unsigned char createdTime[8];

    FILETIME ftCreate, ftAccess, ftWrite;
    SYSTEMTIME stime ;

    if (argc < 2) {
        cout << "Must enter the file name." << endl;
        return 0;
    }
    LPCSTR pszFile = argv[1];
    HANDLE hFile = CreateFile(pszFile, 
                   GENERIC_READ, 
                   (DWORD) 0, 
                   (LPSECURITY_ATTRIBUTES) NULL, 
                   OPEN_EXISTING, 
                   FILE_ATTRIBUTE_NORMAL, 
                   (HANDLE) NULL); 
    if (hFile == INVALID_HANDLE_VALUE) { 
        cout << "Could not open file " << pszFile
             << " for reading (error " << GetLastError() << ")." << endl;
        return 0;
    }
    cout << "Opened file " << pszFile << " for reading." << endl;

    if (!GetFileTime(hFile, &ftCreate, &ftAccess, &ftWrite)) {
        cout << "GetFileTime failed (error " << GetLastError() << ")." << endl;
        return 0;
    }
    FileTimeToSystemTime( &ftCreate, &stime );  // convert to structure
    cout << setfill('0');
    cout << "This is the Create date: "
         << setw(2) << stime.wMonth << "/" 
         << setw(2) << stime.wDay << "/" 
         << stime.wYear << "     Time:"  
         << stime.wHour <<":" 
         << stime.wMinute << ":"
         <<stime.wSecond 
         << endl;

    FileTimeToSystemTime( &ftAccess, &stime );  // convert to structure
    cout << "This is the Access date: "
         << setw(2) << stime.wMonth << "/" 
         << setw(2) << stime.wDay << "/" 
         << stime.wYear << "     Time:"  
         << setw(2) << stime.wHour <<":" 
         << setw(2) << stime.wMinute << ":"
         << setw(2) << stime.wSecond 
         << endl;

    FileTimeToSystemTime( &ftWrite, &stime );  // convert to structure
    cout << "This is the Write  date: "
         << setw(2) << stime.wMonth << "/" 
         << setw(2) << stime.wDay << "/" 
         << stime.wYear << "     Time:"  
         << setw(2) << stime.wHour <<":" 
         << setw(2) << stime.wMinute << ":"
         << setw(2) << stime.wSecond 
         << endl;

    memcpy(createdTime, &stime, 8);

    cout << endl;
    cout << "The bytes of createdTime as they are stored in memory:" << endl;
    cout << hex;
    for (int i = 0; i < 8; i++) {
        cout << "  0x" << setw(2) << unsigned(createdTime[i]);
    }
    cout << endl;
    return 0;
}

Output on my Windows XP system with a particular file in a particular directory:
Code:
F:\cprogs\test>testfiletime /home/dave/ae.txt Opened file /home/dave/ae.txt for reading. This is the Create date: 10/28/2006 Time:19:29:59 This is the Access date: 06/14/2007 Time:23:24:11 This is the Write date: 10/28/2006 Time:19:29:59 The bytes of createdTime as they are stored in memory: 0xd6 0x07 0x0a 0x00 0x06 0x00 0x1c 0x00

Regards,

Dave
Last edited by davekw7x : 01-Jul-2008 at 14:11.
 
 

Recent GIDBlogProgramming ebook direct download available by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
constructors/classes mapes479 C++ Forum 3 19-Nov-2006 18:34
real quick crash question kangol848 Computer Software Forum - Windows 1 02-Aug-2006 01:53
a quick question ap6118 C++ Forum 5 30-Jan-2006 22:54
Question over Time program SergeDrago C++ Forum 3 15-Nov-2005 16:46

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 03:05.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.