Mega Code Archive

 
Categories / C / Development
 

Convert time_t value to tm structure as UTC time

#include <stdio.h> #include <time.h> #define PST (-8) #define CET (1) #define BJ (8) int main () {   time_t rawtime;   struct tm *p;   time ( &rawtime );   p = gmtime ( &rawtime );   printf ("Time in Los Angeles: %2d:%02d\n", p->tm_hour+PST, p->tm_min);   printf ("Time in Berlin:      %2d:%02d\n", p->tm_hour+CET, p->tm_min);   printf ("Time in Bei Jing:   %2d:%02d\n", p->tm_hour+BJ, p->tm_min);      return 0; }