This blog is under construction

Saturday, 5 May 2012

localtime example in C

Header file:
    time.h

Synopsis:
     struct tm *localtime(const time_t *t1);

Description:
     It converts calendar time t1 to local time(broken time - returns structure tm).


localtime function C example:


  #include<stdio.h>
  #include<time.h>
  int main() {
        time_t tp;
        struct tm *ts;
        char *str;
        tp = time(NULL);
        ts = localtime(&tp);
        str = asctime(ts);
        printf("%s", str);
        return 0;
  }




  Output:
  jp@jp-VirtualBox:~/cpgms/time$ ./a.out
  Sat May  5 23:55:17 2012



No comments:

Post a Comment