This blog is under construction

Sunday, 6 May 2012

strftime example in C

Header file:
    time.h

Synopsis:
     size_t strftime(char *str, size_t sz, const char *fmt,
                                        const struct tm *tp);

Description:
     Date and time information in *tp is formatted based on the format string in fmt and the result is placed inside the character array(pointer) str of size sz.

strftime function C example:


  #include<stdio.h>
  #include<time.h>
  int main() {
        time_t tp;
        struct tm *ts;
        int size;
        char str[100];
        tp = time(NULL);
        ts = localtime(&tp);
        size = strftime(str, 100, "%a %b %d %H:%M:%S %Y\n", ts);
        printf("%s", str);
        return 0;
  }




  Output:
  jp@jp-VirtualBox:~/cpgms/time$ ./a.out
  Sun May 06 00:01:55 2012



2 comments:

  1. Hant Singh Rajput in his web series and find more details of Hant singh Rajput and many more for your information. Share to others

    ReplyDelete
  2. Do you need Finance? Are you looking for Finance? Are you looking for finance to enlarge your business? We help individuals and companies to obtain finance for business expanding and to setup a new business ranging any amount. Get finance at affordable interest rate of 3%, Do you need this finance for business and to clear your bills? Then send us an email now for more information contact us now via (financialserviceoffer876@gmail.com) whats-App +918929509036 Dr James Eric Finance Pvt Ltd Thanks

    ReplyDelete