So I'm writing a program to mimic the "find" command in linux. I have everything taken care of, but I cannot figure out how to format the string from ctime, mtime and atime.

I know the arguments are struct time_t, but I can't find to convert it to a formatable string.

Part of what I have is below. it won't work due to the error " error: cannot convert '__time_t' to 'const tm' for argument '4' to 'size_t strftime(char*, size_t, const char*, const tm*)'

Ideally, I want something like this:

cout << strftime(mBuf, 18, "%I:%M:%S-%m/%d/%y", (&sb.st_mtime));

where sb is the stat struct. It should print in the format: HH:MM:SS-MM/DD/YY

I'm sure the answer is something simple, but I cannot figure it out.

According this link the data type of the file times in the stat structure are the same as time_t. Therefore all you have to do is call localtime() to get struct tm, for example

cout << strftime(mBuf, 18, "%I:%M:%S-%m/%d/%y", localtime(&sb.st_mtime));

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.