utc时间和不同时区之间的转换程序

 1 static const int days_per_month_in_leapyear      [13]        = { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
 2 static const int days_per_month_in_commonyear    [13]        = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
 3 // ......
 4 // year,month,day中存储当前日期
 5 void UTC2Timezone(long utctime, int n_timezone, int *year, int *month, int *day)
 6 {
 7     int * days_per_month;
 8     utctime /= 10000;
 9     utctime += n_timezone;
10     days_per_month = *year % 4 == 0 ? days_per_month_in_leapyear : days_per_month_in_commonyear ;
11     if(utctime >= 24)
12     {
13         (*day)++;
14         if( day > days_per_month[*month] )
15             (*month)++;
16         if(*month > 12)
17             (*year)++;
18     }
19     else if(utctime < 0)
20     {
21         (*day)--;
22         if(*day < 1)
23             (*month)--;
24         if(*month < 1)
25             (*year)--;
26     }
27     *month %= 12;
28     //days_per_month = *year % 4 == 0 ? days_per_month_in_leapyear : days_per_month_in_commonyear ;
29     day %= days_per_month[month];
30 }
31 //......

转载于:https://www.cnblogs.com/wangxuchu/archive/2012/04/19/2457834.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值