UNIX时间戳转东八区北京日期时间格式

#include <stdio.h>
#include <time.h>

const int ciday_seconds  = 3600 *24;//86400
const int cileapyear_seconds = 3600 *24 *365;

int isLeapYear(int year)//是平年返回0 否则返回1
{
    return (year%400==0 || (year%100 && year%4==0 ))
            ?1:0;
}
const int DaysMonth[2][12] =
{
    {31,28,31,30,31,30,31,31,30,31,30,31},
    {31,29,31,30,31,30,31,31,30,31,30,31}
};
//确定年月日 0返回
int getDaysFromYearAndMonth(int y,int m)
{
    return m<13 && m>0?DaysMonth[isLeapYear(y)][m]:0;
}

int main(void)
{
    //0010 1100 = 32 + 8+ 4== 44 + 1980
    //1489763292 --东八区-- > 2017/3/17 23:8:12
    //1484665692 ----------> 2017/1/17 23:8:12

    int timestamp = 0;//21亿多刚刚到2038年
    scanf("%d",&timestamp);
    clock_t begin = clock();

    timestamp += 3600 *8;      //东八区  提前加上八个小时
    int y,m,d,h=0,min=0,sec=0;
    int temp =timestamp;
    for(y = 1970; ; y++)
    {
        temp -= isLeapYear(y)*ciday_seconds + cileapyear_seconds;
        if(temp >0)
            timestamp = temp;
        else
            break;
    }
    temp = timestamp;

    for(m=1;m<13; ++m)
    {
        temp -= getDaysFromYearAndMonth(y,m) * ciday_seconds;
        if(temp >0)
            timestamp = temp;
        else
            break;
    }
    temp = timestamp;

    for(d=1;d<=getDaysFromYearAndMonth(y,m);++d)
    {
        temp -= ciday_seconds;
        if(temp >0)
            timestamp = temp;
        else
            break;
    }
    sec = timestamp %60;
    min = timestamp /60 ;

    h = min / 60;
    min %= 60;
    begin = clock() - begin;
    printf("%4d/%02d/%02d %02d:%02d:%02d\n",y,m,d,h,min,sec);

    printf("It takes me  %f seconds\n",((float)begin/CLOCKS_PER_SEC));
    return 0;
}