Home » Code Snippets » How do I get the date a file was last modified?

Sponsored Links

 

How do I get the date a file was last modified?

Attention: open in a new window. PDFPrintE-mail

I want to use date/time that a file was modified. I use stat() function to get file attributes and strftime() function to make format output of date and time. And this is a example:

 
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <iostream>
 
 
int main(int argc, char* argv[])
{
 struct  stat attr;
 int result = stat(argv[0], &amp;attr);
 if (result != 0)
 return 0;
 
 tm* time = gmtime(&amp;attr.st_mtime);
 char time_buf[30]={0};
 strftime(time_buf, 30, "%#d %B %Y - %H:%M:%S", time);
 std::cout << time_buf << std::endl;
 
 return 0;
}
 
© www.sas.bg

 

 

Comments
Add New RSS
+/-
Write comment
Name:
Email:
 
Title:
UBBCode:
[b] [i] [u] [url] [quote] [code] [img] 
 
 
:angry::0:confused::cheer:B):evil::silly::dry::lol::kiss::D:pinch:
:(:shock::X:side::):P:unsure::woohoo::huh::whistle:;):s
:!::?::idea::arrow:
 
Please input the anti-spam code that you can read in the image.