2Fragen zum umgang mit Datumsangaben in c++



  • so hoffe mal die überschrift geht nicht allzuweit am thema vorbei

    meine erste frage betrifft folgendes

    time_t rawtime;
       time ( &rawtime );
      room.gDATE = ctime (&rawtime);
    

    in dem string gDATE habe ich anschließend
    eine datumsangabe in folgenden format Fri Jul 22 23:54:11 2005
    allerdings anscheinend mit zeilenumbruch wie kann ich diesen entfernen?

    meine 2Frage betrifft

    WIN32_FIND_DATA fd;
        FILETIME ftLastWriteTime;
    

    es heist das von dieser funktion kommende datum für den letzten schreibvorgang einer datei kommt im Format UTC wie kann ich dieses umwandeln in ein lesbares Format



  • Auf ne Frage zu C++, gemäss deiner Überschrift, würde ich die Frage dann auch im
    C++ Forum stellen. Da sich der Inhalt jedoch nicht auf C++ bezieht sondern auf
    Windows API würde ich die Frage besser im WINAPI Forum stellen.
    Wie auch immer, hier bist du falsch. 😉



  • @redhead

    time ist soweit ich weis ansi c
    WIN32_FIND_DATA fd; ist glaub ich winapi
    und mit der überschrift wollt ich nur darauf hinweisen das ich in c++ progge
    daher wenn es in c++ ne bessere variante gibt das problem zu lösen
    kann man auch diese angeben

    soviel zu deinem ich bin hier falsch ( ich bin hier richtig und falsch ist halt ansichtsache )
    übrigens danke für deinen hilfreichen post



  • Handbuch

    The string result produced by ctime contains exactly 26 characters and has the form:

    Wed Jan 02 02:03:55 1980\n\0
    0123456789012345678901234 5

    Entfernen kannst du ihn in dem du

    room.gDate[24]=0x00
    setzt.

    Für die andere Frage MSDN zeitfunktionen oder Google



  • @PAD danke für die hilfe deine lösung funktioniert super

    zum 2 problem ich habe schon google auf und ab durchsucht

    nach WIN32_FIND_DATA fd; und ftLastWriteTime; und da war nicht wirklich etwas zu finden



  • Die Informationen die du suchst findest du hier

    Zitat aus MSDN übrigens im Internet vefügbar

    WIN32_FIND_DATA
    The WIN32_FIND_DATA structure describes a file found by the FindFirstFile, FindFirstFileEx, or FindNextFile function. 
    
    typedef struct _WIN32_FIND_DATA {
      DWORD    dwFileAttributes; 
      FILETIME ftCreationTime; 
      FILETIME ftLastAccessTime; 
      FILETIME ftLastWriteTime; 
      DWORD    nFileSizeHigh; 
      DWORD    nFileSizeLow; 
      DWORD    dwReserved0; 
      DWORD    dwReserved1; 
      TCHAR    cFileName[ MAX_PATH ]; 
      TCHAR    cAlternateFileName[ 14 ]; 
    } WIN32_FIND_DATA, *PWIN32_FIND_DATA; 
    Members
    dwFileAttributes 
    Specifies the file attributes of the file found. This member can be one or more of the following values. Attribute Meaning 
    FILE_ATTRIBUTE_ARCHIVE The file or directory is an archive file or directory. Applications use this attribute to mark files for backup or removal. 
    FILE_ATTRIBUTE_COMPRESSED The file or directory is compressed. For a file, this means that all of the data in the file is compressed. For a directory, this means that compression is the default for newly created files and subdirectories. 
    FILE_ATTRIBUTE_DIRECTORY The handle identifies a directory. 
    FILE_ATTRIBUTE_ENCRYPTED The file or directory is encrypted. For a file, this means that all data in the file is encrypted. For a directory, this means that encryption is the default for newly created files and subdirectories. 
    FILE_ATTRIBUTE_HIDDEN The file or directory is hidden. It is not included in an ordinary directory listing. 
    FILE_ATTRIBUTE_NORMAL The file or directory has no other attributes set. This attribute is valid only if used alone. 
    FILE_ATTRIBUTE_OFFLINE The file data is not immediately available. This attribute indicates that the file data has been physically moved to offline storage. This attribute is used by Remote Storage, the hierarchical storage management software. Applications should not arbitrarily change this attribute. 
    FILE_ATTRIBUTE_READONLY The file or directory is read-only. Applications can read the file but cannot write to it or delete it. In the case of a directory, applications cannot delete it. 
    FILE_ATTRIBUTE_REPARSE_POINT The file has an associated reparse point. 
    FILE_ATTRIBUTE_SPARSE_FILE The file is a sparse file. 
    FILE_ATTRIBUTE_SYSTEM The file or directory is part of the operating system or is used exclusively by the operating system. 
    FILE_ATTRIBUTE_TEMPORARY The file is being used for temporary storage. File systems attempt to keep all of the data in memory for quicker access, rather than flushing it back to mass storage. A temporary file should be deleted by the application as soon as it is no longer needed. 
    
    ftCreationTime 
    A FILETIME structure that specifies when the file or directory was created. If the underlying file system does not support creation time, ftCreationTime is zero. 
    ftLastAccessTime 
    A FILETIME structure. For a file, the structure specifies when the file was last read from or written to. For a directory, the structure specifies when the directory was created. For both files and directories, the specified date will be correct, but the time of day will always be set to midnight. If the underlying file system does not support last access time, ftLastAccessTime is zero. 
    ftLastWriteTime 
    A FILETIME structure. For a file, the structure specifies when the file was last written to. For a directory, the structure specifies when the directory was created. If the underlying file system does not support last write time, ftLastWriteTime is zero. 
    nFileSizeHigh 
    Specifies the high-order DWORD value of the file size, in bytes. This value is zero unless the file size is greater than MAXDWORD. The size of the file is equal to (nFileSizeHigh * (MAXDWORD+1)) + nFileSizeLow. 
    nFileSizeLow 
    Specifies the low-order DWORD value of the file size, in bytes. 
    dwReserved0 
    If the dwFileAttributes member includes the FILE_ATTRIBUTE_REPARSE_POINT attribute, this member specifies the reparse tag. Otherwise, this value is undefined and should not be used. 
    dwReserved1 
    Reserved for future use. 
    cFileName 
    A null-terminated string that is the name of the file. 
    cAlternateFileName 
    A null-terminated string that is an alternative name for the file. This name is in the classic 8.3 (filename.ext) file name format. 
    Remarks
    If a file has a long file name, the complete name appears in the cFileName field, and the 8.3 format truncated version of the name appears in the cAlternateFileName field. Otherwise, cAlternateFileName is empty. As an alternative, you can use the GetShortPathName function to find the 8.3 format version of a file name.
    
    Not all file systems can record creation and last access time and not all file systems record them in the same manner. For example, on NT FAT, create time has a resolution of 10 milliseconds, write time has a resolution of 2 seconds, and access time has a resolution of 1 day (really, the access date). On NTFS, access time has a resolution of 1 hour. For more information, see File Times. 
    
    Requirements 
      Windows NT/2000/XP: Included in Windows NT 3.1 and later.
      Windows 95/98/Me: Included in Windows 95 and later.
      Header: Declared in Winbase.h; include Windows.h.
      Unicode: Declared as Unicode and ANSI structures.
    
    See Also
    File I/O Overview, File I/O Structures, FILETIME, FindFirstFile, FindFirstFileEx, FindNextFile, FileTimeToLocalFileTime, FileTimeToSystemTime, GetShortPathName
    


  • mein problem ist ja nicht das ich es ausgelesen bekomme das funktioniert ja
    nur anscheinend scheigen sich google und msdn drüber aus wie ich aus dem "zahlensalat" (soll UTC time format sein) ein lesbares datum bekomme.



  • hier wieder ein Auszug aus der MSDN
    erzeugt mit Microsoft Visual C 6.0 eine File mit extenstion .c angelgt filetime geschrieben und f1 gedrückt

    FILETIME
    The FILETIME structure is a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601 (UTC).

    typedef struct _FILETIME {
    DWORD dwLowDateTime;
    DWORD dwHighDateTime;
    } FILETIME, *PFILETIME;
    Members
    dwLowDateTime
    Specifies the low-order 32 bits of the file time.
    dwHighDateTime
    Specifies the high-order 32 bits of the file time.
    Remarks
    To convert a FILETIME structure into a time that is easy to display to a user, use the FileTimeToSystemTime function.

    It is not recommended that you add and subtract values from the FILETIME structure to obtain relative times. Instead, you should

    Copy the resulting FILETIME structure to a ULARGE_INTEGER structure.
    Use normal 64-bit arithmetic on the ULARGE_INTEGER value.
    Not all file systems can record creation and last access time and not all file systems record them in the same manner. For example, on NT FAT, create time has a resolution of 10 milliseconds, write time has a resolution of 2 seconds, and access time has a resolution of 1 day (really, the access date). On NTFS, access time has a resolution of 1 hour. Therefore, the GetFileTime function may not return the same file time information set using the SetFileTime function. Furthermore, FAT records times on disk in local time. However, NTFS records times on disk in UTC. For more information, see File Times.

    Requirements
    Windows NT/2000/XP: Included in Windows NT 3.1 and later.
    Windows 95/98/Me: Included in Windows 95 and later.
    Header: Declared in Winbase.h; include Windows.h.

    von filtime nach systemtime und dann mit sprintf formatieren

    char buffer[80+1];
    SYSTEMTIME SystemTime;
      FILETIME FileTime;
    ....
       FileTimeToSystemTime(&FileTime,&SystemTime);
      sprintf(buffer,"%4.4i/%2.2i/%2.2i %2.2i.%2.2i.%2.2i,",
    	  SystemTime.wYear,SystemTime.wMonth,SystemTime.wDay,
    	  SystemTime.wHour,SystemTime.wMinute,SystemTime.wSecond);
    


  • Noch mehr MSDN:

    #include <windows.h>
    
    // GetLastWriteTime - Retrieves the last-write time and converts
    //                    the time to a string
    //
    // Return value - TRUE if successful, FALSE otherwise
    // hFile      - Valid file handle
    // lpszString - Pointer to buffer to receive string
    
    BOOL GetLastWriteTime(HANDLE hFile, LPTSTR lpszString)
    {
        FILETIME ftCreate, ftAccess, ftWrite;
        SYSTEMTIME stUTC, stLocal;
    
        // Retrieve the file times for the file.
        if (!GetFileTime(hFile, &ftCreate, &ftAccess, &ftWrite))
            return FALSE;
    
        // Convert the last-write time to local time.
        FileTimeToSystemTime(&ftWrite, &stUTC);
        SystemTimeToTzSpecificLocalTime(NULL, &stUTC, &stLocal);
    
        // Build a string showing the date and time.
        wsprintf(lpszString, TEXT("%02d/%02d/%d  %02d:%02d"),
            stLocal.wMonth, stLocal.wDay, stLocal.wYear,
            stLocal.wHour, stLocal.wMinute);
    
        return TRUE;
    }
    


  • @asdrubael und PAD

    danke für die geduld mit mir dank eurer hilfe hab ich das nun hinbekommen

    für diejenigen die es interessiert hier mal die funktion für die ich die filetime brauchte

    std::string showdir(const char *directory,const char *path, std::string body)
    {
            WIN32_FIND_DATA fd;
            HANDLE hfind;
    
            char buf[255];
            char newbuf[255];
            int i;
            int j;
            int countdir;
            int countfile;
            std::string bodytemp; //soll kurzzeitig die dateiverknüpfungen aufnehmen
    
            strcpy(buf,directory);
    
            i = 0;
            j = 0;
            countdir = 0;
            countfile= 0;
            while( buf[i] != 0 ) // hier werden in der pfadangabe alle vorkommenden / durch \\ ersetzt
             {
               if( buf[i] == '/' )
               {
                 newbuf[j] = '\\';
                 newbuf[j+1] = '\\';
                 j+=2;
               }
               else
               {
                 newbuf[j] = buf[i];
                 j++;
               }
                 i++;
               }
                 newbuf[j] = 0;
                 strcat( newbuf , "*.*" );
    
            hfind = FindFirstFile(newbuf,&fd);
    
      SYSTEMTIME stUTC, stLocal;
    
            while(hfind != INVALID_HANDLE_VALUE) // hier werden die urls zusammengestellt
            {
              if ((std::string)fd.cFileName != "." && (std::string)fd.cFileName != ".." && (std::string)fd.cFileName != ".htaccess" && (std::string)fd.cFileName != ".htpasswd" && fd.dwFileAttributes != FILE_ATTRIBUTE_HIDDEN)
              {
    
        FileTimeToSystemTime(&fd.ftLastWriteTime, &stUTC);
        SystemTimeToTzSpecificLocalTime(NULL, &stUTC, &stLocal);
    
               if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
                { 
                    sprintf(newbuf,"<TR><TD><A HREF=\"%s%s\">%s</a></TD>\t\t<TD>am %02d.%02d.%02d um %02d:%02d:%02d</TD><TD>-</TD><TD> Verzeichniss</TD></TR>\n",path,fd.cFileName,fd.cFileName,(int)stLocal.wDay, (int)stLocal.wMonth, (int)stLocal.wYear,(int)stLocal.wHour, (int)stLocal.wMinute, (int)stLocal.wSecond);
                       body += newbuf;
                    countdir++;
                }
                else
                { 
                    sprintf(newbuf,"<TR><TD><A HREF=\"%s%s\">%s</a></TD>\t\t<TD>am %02d.%02d.%02d um %02d:%02d:%02d</TD><TD>%d Bytes</TD><TD> BYTES???</TD></TR>\n",path,fd.cFileName,fd.cFileName,(int)stLocal.wDay, (int)stLocal.wMonth, (int)stLocal.wYear,(int)stLocal.wHour, (int)stLocal.wMinute, (int)stLocal.wSecond,fd.nFileSizeLow);
                       bodytemp += newbuf;
                    countfile++;
                }
              }
                    if(!FindNextFile(hfind,&fd))
                            break;
            }
    
            FindClose(hfind);
                   sprintf(newbuf,"der ordner enthielt %d Verzeichnisse und %d Ordner",countdir,countfile);
    
    body +=bodytemp; // hier werden die dateilinks an die verzeichnislinks angehängt
    body +="</TABLE></DIV><hr>";
    body +=newbuf;
    
    return body; 
    
    }
    

Anmelden zum Antworten