Skip to content

Instantly share code, notes, and snippets.

@StrikeW
Created April 20, 2014 15:25
Show Gist options
  • Save StrikeW/11116799 to your computer and use it in GitHub Desktop.
Save StrikeW/11116799 to your computer and use it in GitHub Desktop.
format st_mtime which get from stat()
#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, &lt); /* convert to struct tm */
strftime(mtime, sizeof mtime, "%a, %d %b %Y %T", &lt);
printf("%s\n", mtime);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment