int tz_minuteswest/* minutes west of Greenwich */
int tz_dsttime/* type of DST correction */
}
用这个试试
你要知道时区,才能算出那里的时间。C语言可以算出你的当地时间和UTC(格林尼治时间),用你的计算机本身的设置。给出时区,就可推算。
中国北京时间是东八区。美国凤凰城西7区。冰岛=格林尼治时间。
下面程序计算美国凤凰城,中国北京,和冰岛时间:
#include <stdio.h>
#include <time.h>
#define MST (-7)
#define UTC (0)
#define CCT (+8)
int main ()
{
time_t rawtime
tm * ptm
time ( &rawtime )
ptm = gmtime ( &rawtime )
puts ("Current time around the World:")
printf ("Phoenix, AZ (U.S.) : %2d:%02d\n", (ptm->tm_hour+MST)%24, ptm->tm_min)
printf ("Reykjavik (Iceland) : %2d:%02d\n", (ptm->tm_hour+UTC)%24, ptm->tm_min)
printf ("Beijing (China) : %2d:%02d\n", (ptm->tm_hour+CCT)%24, ptm->tm_min)
return 0
}
getlocaltime里面是没有时区信息的。
你可以这样:
time_t time_utc = 0struct tm *p_tm_time
int time_zone = 0
p_tm_time = localtime( &time_utc ) //转成当地时间
time_zone = ( p_tm_time->tm_hour > 12 ) ? ( p_tm_time->tm_hour-= 24 ) : p_tm_time->tm_hour
把0时间转为当地时间,得到的是带时区的结果。