CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2001
    Location
    Kerala
    Posts
    50

    strftime() is not functioning for me...

    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



  2. #2
    Join Date
    Feb 2001
    Location
    Sydney, Australia
    Posts
    1,909

    Re: strftime() is not functioning for me...

    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)
    [email protected] | ICQ:57404554 | http://soukhov.com

    Member of Russian Software Developer Network http://rsdn.ru
    Best regards,
    Igor Sukhov

    www.sukhov.net

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured