Posted By

oznek on 08/13/10


Tagged


Versions (?)

Timezone information in C (offset, names, etc)


 / Published in: C
 

  1. #include<time.h>
  2. #include<stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5.  
  6. /*
  7.   can be called in shell with:
  8.  
  9.   shell$ TZ="Europe/Rome" ./teste
  10.  
  11.  */
  12.  
  13. int main(int argc, char *argv[])
  14. {
  15. time_t now_time;
  16. struct tm *now;
  17.  
  18. // Forcing timezone
  19.  
  20. //setenv("TZ", "Europe/Rome", 1);
  21. //tzset();
  22.  
  23. time(&now_time);
  24. printf("Now (unix timestamp): %ld \n\n", now_time);
  25.  
  26. now = localtime(&now_time);
  27.  
  28. printf(">>>> Now (gmt offset %ld): %s\n", now->tm_gmtoff, asctime(now));
  29. printf(">>>> isDst: %d\n", now->tm_isdst);
  30. printf(">>>> tzname: %s\n", now->tm_zone);
  31.  
  32.  
  33. return 0;
  34. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: oznek on August 13, 2010

Linux gcc

You need to login to post a comment.