Results 1 to 6 of 6

Thread: How to use the strftime() in C++

  1. #1
    Join Date
    Dec 2009
    Posts
    31

    How to use the strftime() in C++

    Hi, I can not have the knowledge about the strftime() function of the C++ programming language. I had learned the C++ language even though I can not anything about the strftime() function of the C++ language. So, I would like to know about the strftime() function of the C++ language. I also would like to know about that how can I use the function strftime() in the C++ programming. Hence, Can anyone knows about the strftime() function of the C++ language????

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Use the strftime() in C++

    The strftime() function can be used in the C++ language to format the time in the given specified form to string. The strftime() function can copies into the variable the content of format, expanding its format tags into the corresponding values that can be specified by the variable tmpr, with a limit of mxsz characters. The following can be the syntax of the strftime() function of the C++ language :
    Code:
    size_t strftime ( char * pr, szt mxsz, const char * frmt, 
      const struct tm * tmpr );
    Last edited by Praetor; 02-03-2010 at 04:33 PM.

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    How to use the strftime()

    The following can be the program on the strftime() function of the C++ language that can be used to format the time into the string. Go through the following code :
    Code:
    #include <stdio.h>
    #include <time.h>
    int main ()
    {
      tmt rwtm;
      struct t * tmnf;
      char bfr [80];
      time ( &rwtm );
      tmnf = localtime ( &rwtm );
      strftime (bfr,80,"Now it's %I:%M%p.",tmnf);
      puts (bfr);
      return 0;
    }
    The above code generate the following Output :
    Code:
    Now it's 03:21PM.

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    The strftime() Function

    The following can be the parameters of the strftime() function of the C++ language as :
    1. mxsz : This parameter can be used in the C++ to hold the maximum number of the characters that can be copied into the pointer variable.
    2. frmt : This parameter can be used in the C++ to hold the C string that can containing any combination of special format specifiers and the regular characters.
    3. pr : This parameter can be used in the C++ to hold pointer that can be to the destination array where the resultant C string can be copied.

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Re: How to use the strftime() in C++

    The following format specifiers can be replaced by the functions that can be to the corresponding values that can be use to represent the time specified in variable of the time pointer as follows :
    %A can be replaced by the locale's full weekday name.
    %C can be replaced by the century number (the year divided by 100 and truncated to an integer) as a decimal number [00,99].
    %a can be replaced by the locale's abbreviated weekday name.
    %D can be the same as %m/%d/%y.
    %B can be replaced by the locale's full month name.
    %e can be replaced by the day of the month as a decimal number [1,31]; a single digit can be preceded by a sp
    %c can be replaced by the locale's appropriate date and time representation.
    %b can be replaced by the locale's abbreviated month name.
    %d can be replaced by the day of month as a decimal number [01,31].

  6. #6
    Join Date
    Nov 2005
    Posts
    1,323

    Re: How to use the strftime() in C++

    The following program can uses the strftime() function to format the time into the string as :
    Code:
    #include <iostream>
          #include <ctime>
          #include <cerrno>
          int main()
          {
               tm_t crtm = time(0);
               m nw=*localtime(&crtm);
               char dst[BFSZ]={0};
               const char frmt[]="%A, %B %d %Y. The time can be %X";
               if (strftime(dst, sizeof(dst)-1, frmt, &now)>0)
               std::cout<<dst<<std::endl;
               else
               std::cerr<<"strftime failed. Errno code: "<<errno<<std::endl;
          }
    I hope from the above program you can understands the working of the strftime() function.

Similar Threads

  1. strftime() in PHP
    By REDBULL in forum Software Development
    Replies: 3
    Last Post: 21-11-2009, 12:41 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,715,132,083.34780 seconds with 17 queries