Click to See Complete Forum and Search --> : strftime() is not functioning for me...


shinto
September 12th, 2001, 11:41 AM
the following code is used:
char strtime[15];
time_t tms;
time(&tms);

printf("\n %s",ctime(&tms));

strftime(strtime,9,"%m",&tms);

printf("\n %s",strtime);

The expected output from the second printf is 09 when run on September. But some wrong value is printed. I m using DIGITAL unix.

Please help me to resolve

-shinto

Igor Soukhov
September 13th, 2001, 11:09 AM
Use localtime or gmtime to convert tmt variable to tm type.


#include <time.h>
#include <stdio.h>


void main()
{
char strtime[15];
time_t tms;
time(&tms);

tm *ptm = localtime(&tms);

strftime(strtime, 9,"%m",ptm);

printf("\n %s",strtime);
}





Please - rate answer if it helped you
It gives me inspiration when I see myself in the top list =)

Best regards,

-----------
Igor Soukhov (Brainbench/Tekmetrics ID:50759)
igor@soukhov.com | ICQ:57404554 | http://soukhov.com

Member of Russian Software Developer Network http://rsdn.ru