This blog is under construction

Saturday, 5 May 2012

gmtime example in C

Header file:
    time.h

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

Description:
     It converts the calendar time t1 into UTC/GMT.


gmtime function C example:



  #include<stdio.h>
  #include<time.h>
  int main() {
        time_t tp;
        struct tm *t;
        char *str;
        tp = time(NULL);
        t = gmtime(&tp);
        str = asctime(t);
        printf("GMT:\n%s", str);
        str = ctime(&tp);
        printf("IST:\n%s", str);
        return 0;
  }



  Output:
  jp@jp-VirtualBox:~/cpgms/time$ ./a.out
  GMT:
  Sat May  5 18:20:10 2012
  IST:
  Sat May  5 23:50:10 2012





No comments:

Post a Comment