您的位置:首页 > 其它

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

2012-04-19 20:51 267 查看
static const int days_per_month_in_leapyear      [13]        = { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
static const int days_per_month_in_commonyear    [13]        = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
// ......
// year,month,day中存储当前日期
void UTC2Timezone(long utctime, int n_timezone, int *year, int *month, int *day)
{
int * days_per_month;
utctime /= 10000;
utctime += n_timezone;
days_per_month = *year % 4 == 0 ? days_per_month_in_leapyear : days_per_month_in_commonyear ;
if(utctime >= 24)
{
(*day)++;
if( day > days_per_month[*month] )
(*month)++;
if(*month > 12)
(*year)++;
}
else if(utctime < 0)
{
(*day)--;
if(*day < 1)
(*month)--;
if(*month < 1)
(*year)--;
}
*month %= 12;
//days_per_month = *year % 4 == 0 ? days_per_month_in_leapyear : days_per_month_in_commonyear ;
day %= days_per_month[month];
}
//......
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐