#include <stdio.h> #include <stdlib.h> #include <time.h> void utc2local(char *st1,char *st2,int dh){ time_t utc,local; struct tm ts,ts2; strptime(st1, "%Y-%m-%dT%H:%M:%S", &ts2); utc=mktime(&ts2); local=utc+dh*3600; ts = *localtime(&local); strftime(st2, 80, "%Y-%m-%dT%H:%M:%SZ", &ts); }
int main(void) { time_t now; struct tm ts,ts2; char b1[80],b2[80];
time(&now); ts = *localtime(&now); strftime(b1, sizeof(b1), "%a %Y-%m-%d %H:%M:%S %Z", &ts); printf("now localetime = %s\n", b1);
char st[]="2017-03-31T23:09:15Z"; utc2local(st,b2,+8); printf("utc %s +%d --> local %s\n", st,+8,b2); return 0; } |