same date when printing from st_mtime, st_ctime,st_atime

非 Y 不嫁゛ 提交于 2020-12-12 09:53:09

问题


So, I'm supposed to print the date of access of directories, modification and creation, but they all seem to be the same date. Here's my code:

struct* tm date;
struct stat fileStat;


if(options[0] == 1 && options[1] == 0 && options[2] == 0 && options[3] == 0){
        date = localtime(&(fileStat.st_mtime));
        printf("M%02i/%d/%i-%02d:%02d", date->tm_mon,date->tm_mday, (date->tm_year + 1900)%100, date->tm_hour,date->tm_min);
        date = NULL;
      } else if(options[0] == 1 && options[1] == 1 && options[2] == 0 && options[3] == 0){
        date = localtime(&(fileStat.st_atime));
        printf("A%02i/%d/%i-%02d:%02d", date->tm_mon,date->tm_mday, (date->tm_year + 1900)%100, date->tm_hour,date->tm_min);
        date = NULL;
      } else if(options[0] == 1 && options[1] == 0 && options[2] == 1 && options[3] == 0){
        date = localtime(&(fileStat.st_ctime));
        printf("C%02i/%d/%i-%02d:%02d", date->tm_mon,date->tm_mday, (date->tm_year + 1900)%100, date->tm_hour,date->tm_min);
      }

The option stuff is just to select between which one I want to print. Would really appreciate some help on this! Thanks

来源:https://stackoverflow.com/questions/44015747/same-date-when-printing-from-st-mtime-st-ctime-st-atime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!