(C Linux)strftime返回损坏的日期时间
我正在使用以下代码:(C Linux)strftime返回损坏的日期时间,c,linux,time,C,Linux,Time,我正在使用以下代码: char dateModified[101]; setlocale(LC_TIME, "en_US.UTF-8"); //Get address for the file's modified time: struct timespec *timeP = &(filesList[i].mtime); //Translate the time to text strftime(dateModified, 100, "%b %e %Y %R", time
char dateModified[101];
setlocale(LC_TIME, "en_US.UTF-8");
//Get address for the file's modified time:
struct timespec *timeP = &(filesList[i].mtime);
//Translate the time to text
strftime(dateModified, 100, "%b %e %Y %R", timeP);
//Print time since 1970, address of the struct and formatted time
printf("%d %d \'%s\'\n", timeP->tv_sec, timeP, dateModified);
格式化和打印多个文件的上次修改时间。但是,即使时间戳是正确的,格式化的时间也总是不正确的。
有什么问题吗?
某些文件的输出:
TIMESTAMP ADDRESS FORMATTED TIME
1494268890 15343728 '? 0 1852401361 74573639:00'
1494268890 15344048 '? 0 1701605586 74573639:00'
1494268890 15344368 '? 0 1885498010 74573639:00'
1494268889 15344688 '? 0 1900 130561033:00'
(所有时间戳均指向2017年5月8日下午6:41(UTC))注意:
timeP->tv_sec
和timeP
都不是printf
格式规范%d
要求的int
类型。是的,将tv_sec固定为长。至于timeP,我只是想看看地址,这一行不会停留在代码中代码>请不要编辑您发布的代码,这将混淆任何以下评论<代码>%l不是有效的格式说明符。我认为“timespec”是错误的类型:size\t strftime(char*,size\t,const char*,const struct tm*);