首页 > 编程知识 正文

biubiu加速器官网,biubiu加速器永久免费

时间:2023-05-04 18:33:07 阅读:220340 作者:3081

项目中用到了时间转换的功能,计算GMT时间和加上时区后的时间,得到本地时区,我写了一个小程序希望对大家有所帮助!

 

#include <stdio.h>#include <time.h>int main(int argc,char *argv[]){ time_t time_utc; struct tm tm_local; // Get the UTC time time(&time_utc); // Get the local time // Use localtime_r for threads safe localtime_r(&time_utc, &tm_local); time_t time_local; struct tm tm_gmt; // Change tm to time_t time_local = mktime(&tm_local); // Change it to GMT tm gmtime_r(&time_utc, &tm_gmt); int time_zone = tm_local.tm_hour - tm_gmt.tm_hour; if (time_zone < -12) { time_zone += 24; } else if (time_zone > 12) { time_zone -= 24; } char cur_time[256]; strftime (cur_time,256, " %B %A %Y年%m[34m~~H%d[34m~WH[34m~W[m~H~F%Sm~R %c %x %X", &tm_local); printf("LOCAL TIME :%sn", cur_time); strftime(cur_time,256, " %B %A %Y年%m[34m~~H%d[34m~WH[34m~W[m~H~F%Sm~R %c %x %X", &tm_gmt); printf("GMT TIME :%sn", cur_time); printf("Your time zone is +%d. (- is west, + is east)n", time_zone); return 0;}

 

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。