st_atime、st_mtimeとst_ctime

1936 ワード

struct stat定義:
struct stat  
{  
    dev_t       st_dev;     /* ID of device containing file -       ID*/  
    ino_t       st_ino;     /* inode number -inode   */
    mode_t      st_mode;    /*            */  
    nlink_t     st_nlink;   /* number of hard links -         (   )*/  
    uid_t       st_uid;     /* user ID of owner -user id*/  
    gid_t       st_gid;     /* group ID of owner - group id*/  
    dev_t       st_rdev;    /* device ID (if special file) -   ,      */  
    off_t       st_size;    /* total size, in bytes -    ,     */  
    blksize_t   st_blksize; /* blocksize for filesystem I/O -      */  
    blkcnt_t    st_blocks;  /* number of blocks allocated -      */  
    time_t      st_atime;   /* time of last access -      */  
    time_t      st_mtime;   /* time of last modification -      */  
    time_t      st_ctime;   /* time of last status change -         */  
}; 

st_atime、st_mtimeとst_ctimeはいずれも1970年1月1日00:00:00(国際標準時間)から時間記録に到達した時間の秒数を表し、この時間値をカレンダー時間と呼ぶ.どのようにして人間が認識できる時間に転化しますか?この関数を使用します.
#include 
struct tm *localtime(const time_t *timer);

この関数の機能は,1970年1月1日00:00:00からtimerまでの秒数時間を人間が認識できる時間に変換することである.戻り値struct tmの構造は、次のとおりです.
struct tm {
   int tm_sec;         /*  ,   0 59			*/
   int tm_min;         /*  ,   0 59			*/
   int tm_hour;        /*   ,   0 23		*/
   int tm_mday;        /*       ,   1 31	*/
   int tm_mon;         /*   ,   0 11		*/
   int tm_year;        /*  1900    			*/
   int tm_wday;        /*        ,   0 6*/
   int tm_yday;        /*        ,   0 365*/
   int tm_isdst;       /*    					*/    
};

関数の使用方法:
struct tm* t = localtime(&file_message->st_mtime);		//struct stat* file_message
printf("%2d  %2d %02d:%02d ", t->tm_mon+1, t->tm_mday, t->tm_hour, t->tm_min);

注意:tm_mon,tm_wday,tm_ydayはいずれも1を追加します.