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], &attr);
	if (result != 0)
		return 0;

	tm* time = gmtime(&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;
}

Add comment


Security code
Refresh

Joomla SEF URLs by Artio