C language strftime time format sample

  • 2020-04-02 02:12:44
  • OfStack

Function prototype:


size_t strftime (char* ptr, size_t maxsize, const char* format,const struct tm* timeptr );

Code example:


#include <stdio.h>
#include <time.h>
int main ()
{
    time_t rawtime;
    struct tm * timeinfo;
    char buffer [128];
    time (&rawtime);
    timeinfo = localtime (&rawtime);
    strftime (buffer,sizeof(buffer),"Now is %Y/%m/%d %H:%M:%S",timeinfo);
    puts (buffer);
    return 0;
}


Related articles: