Get last modified time of file in linux

后端 未结 3 975
天命终不由人
天命终不由人 2020-12-09 09:57

I am working on a C program where I need to get the last modified time of the file. What the program does is a function loops through each file within a directory and when a

3条回答
  •  醉话见心
    2020-12-09 10:50

    This is one of those cases where timezones matter. You're getting gmtime of the st_mtime. You should instead be using localtime viz.

    strftime(date, 20, "%d-%m-%y", localtime(&(attrib.st_ctime)));
    

    this is because ls uses your timezone information, and when you used gmtime as part of the display, it deliberately omitted any timezone information.

提交回复
热议问题