Linux下有什么函数可以修改时区
最近公司的一个板子要销往国外,之前没接触过时区这块,现在遇到一个很尴尬的问题,就是用户修改好时区后,我不知道通过哪个函数去修改系统里的时区
我有试过直接获得GMT时间后,在time_t类型基础上加上时区*3600后打印的时间是对的,但是系统的时区还是0
请教各位,用什么方法来实现:
#include <stdio.h>#include <time.h>int main(int argc, char **argv){ time_t now; //struct tm *tmutc, *tmlocal; struct tm utc_tm, local_tm; /*获取日历时间*/ time(&now); int tz = 0; scanf("%d", &tz); now += tz * 3600;#if 1 /*转换成tm时间*/ gmtime_r(&now, &utc_tm); /*输出时间*/ printf("%s标准时间为:\t%s", utc_tm.tm_zone, asctime(&utc_tm)); printf("GMT: %ld\n", utc_tm.tm_gmtoff);#else localtime_r(&now, &local_tm); printf("%s时间为:\t%s", local_tm.tm_zone, asctime(&local_tm));#endif return 0;}[root@localhost demo]# ./a.out 8GMT标准时间为: Sun Jun 17 16:41:09 2012GMT: 0