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 //......