yzk376 发表于 2012-4-18 23:06:43

UCT时间转北京时间好处理,但日期怎么办?

 time=(atol((char*)GPS_Time));
 time=(time+80000)%240000; //变换为北京时间

UCT时间转北京时间好处理,但日期怎么办?日期里面的年月日都需要处理,不然日期总是慢8个小时,有没有好的算法?

发表于 2012-4-19 10:12:24

RE:UCT时间转北京时间好处理,但日期怎么办?

通过处理时间,当UTC时间+时差大于24的时候,日期就加1。

TommyWang-28225 发表于 2012-4-19 20:42:54

RE:UCT时间转北京时间好处理,但日期怎么办?

转化到任意时区
static const int days_per_month_in_leapyear                                = { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
static const int days_per_month_in_commonyear                        = { 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;
}
//......

yzk376 发表于 2012-4-24 07:47:32

RE:UCT时间转北京时间好处理,但日期怎么办?

试一试,谢谢!:lol

yzk376 发表于 2012-4-24 10:43:29

RE:UCT时间转北京时间好处理,但日期怎么办?

uct时间怎么可能大于等于24呢???

yzk376 发表于 2012-4-24 10:45:26

RE:UCT时间转北京时间好处理,但日期怎么办?

uct时间怎么可能小于0呢?
页: [1]
查看完整版本: UCT时间转北京时间好处理,但日期怎么办?