微信小程序> 时间时区转换小程序,GMT时间和加上时区后的时间和得到本地时区的小程序

时间时区转换小程序,GMT时间和加上时区后的时间和得到本地时区的小程序

浏览量:3552 时间: 来源:David.li

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

 

#include stdio.h#include time.hint 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  :%s", 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    :%s", cur_time);    printf("Your time zone is +%d. (- is west, + is east)", time_zone);    return 0;}

 

版权声明

即速应用倡导尊重与保护知识产权。如发现本站文章存在版权问题,烦请提供版权疑问、身份证明、版权证明、联系方式等发邮件至197452366@qq.com ,我们将及时处理。本站文章仅作分享交流用途,作者观点不等同于即速应用观点。用户与作者的任何交易与本站无关,请知悉。

产品经理

手机 : 13312967497

擅长 : 小程序流量变现

扫码领取礼包

最新资讯

热门模板

  • 头条
  • 搜狐
  • 微博
  • 百家
  • 一点资讯
  • 知乎