Format a timestamp into text
Posted
by
user1257114
on Stack Overflow
See other posts from Stack Overflow
or by user1257114
Published on 2013-07-03T10:37:05Z
Indexed on
2013/07/03
11:05 UTC
Read the original article
Hit count: 143
I want to get the Modify date of a file and then format it into a human readable date. I am running a C program that gets information on when a particular file was last modified. My C Code contains a sytem cmd which contains a number of egreps, awks, seds separated by pipes. Using sed or awk or something similar, how can I convert 06 to June (This can be any month so an array or something is required) What I am trying to achieve is to end up with a string similar to:
My C code contains:
char string1[100] = "";
#define MAXCHAR 100
FILE *fp;
char str[MAXCHAR], str2[MAXCHAR];
char* filename = "newfile";
/*
stat: run 'stat' on the dtlName file to display status information.
egrep: search for the pattern 'Modify' and print the lines containing it.
awk: Get columns 2 & 3
sed: replace the . with a space, leaving 3 columns of output
awk: only print cols 1 & 2 to newfile
sed: replace '-' with ' ' in newfile
awk: format output in newfile
*/
sprintf(string1, "/bin/stat %s \
| egrep Modify \
| /bin/awk '{print $2, $3}' \
| /bin/sed 's/\\./ /g' \
| /bin/awk '{print $1, $2}' \
| /bin/sed 's/-/ /g' \
| /bin/awk '{print $3,$2\", \"$1,\"at\",$4}' > newfile"
, dtlName);
system(string1);
fp = fopen(filename, "r");
while (fgets(str, MAXCHAR, fp) != NULL)
sprintf(str2,"%s", str);
/* Write information to file */
DisplayReportFile (report);
ReportEntry (report,L"Source file: %s, Created: %s\n\n",dtlName,str2);
© Stack Overflow or respective owner