在线时间0 小时
UID282251
ST金币0
蝴蝶豆0
注册时间2008-10-6
新手上路
- 最后登录
- 1970-1-1
|
发表于 2012-4-19 20:42:54
|
显示全部楼层
a0a.1 0b0c
RE:UCT时间转北京时间好处理,但日期怎么办?
转化到任意时区
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];
}
//...... |
|