Created
April 20, 2014 15:25
-
-
Save StrikeW/11116799 to your computer and use it in GitHub Desktop.
format st_mtime which get from stat()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
#include <stdlib.h> | |
#include <sys/stat.h> | |
#include <time.h> | |
int main(int argc, char *argv[]) | |
{ | |
struct stat st; | |
char *f = "README"; | |
if (stat(f, &st) == -1) { | |
perror("stat"); | |
exit(1); | |
} | |
char mtime[80]; | |
time_t t = st.st_mtime; /*st_mtime is type time_t */ | |
struct tm lt; | |
localtime_r(&t, <); /* convert to struct tm */ | |
strftime(mtime, sizeof mtime, "%a, %d %b %Y %T", <); | |
printf("%s\n", mtime); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment