标签:
实现如下:
#include <stdio.h> #include <unistd.h> #include <fcntl.h> #include <sys/stat.h> #include <stdlib.h> #include <time.h> char* formatdate(char* str, time_t val) { //localtime()将参数timep 所指的time_t 结构中的信息转换成真实世界所使用的时间日期表示方法 strftime(str, 36, "%d.%m.%Y %H:%M:%S", localtime(&val)); return str; } int main() { struct stat fdstat; const char* filename = "test.txt"; //your filename char date[36]; if (stat(filename, &fdstat) == -1) { printf("open error\n"); exit(0); } printf("i-node number:[%d]\n",fdstat.st_ino); printf("st_nlink:[%d]\n", fdstat.st_nlink); printf("st_uid:[%d]\n", fdstat.st_uid); printf("st_gid:[%d]\n", fdstat.st_gid); printf("st_blocks:[%d]\n", fdstat.st_blocks); printf("st_size:[%d]\n", fdstat.st_size); printf("st_atime:[%d]\n", fdstat.st_atime); printf("st_mtime:[%d]\n", fdstat.st_mtime); printf("Access: %s\n", formatdate(date, fdstat.st_atime)); printf("Modify: %s\n", formatdate(date, fdstat.st_mtime)); printf("Change: %s\n", formatdate(date, fdstat.st_ctime)); return 0; }
标签:
原文地址:http://www.cnblogs.com/how-are-you/p/5634842.html