android13位的时间戳,13位的时间戳肿么转换成标准时间

使用范例

char *str=1320718222932;

long long time1;

sscanf(str,%I64d,&time);

CString strTime=MillSecond2LocalTime(time,8);

/

int CTimeChangeDlg::IsLeap(unsigned short year)

{

return ((year%4==0)&&(year%100!=0)||(year%400==0));

}

CString CTimeChangeDlg::MillSecond2LocalTime(long long time,long timezone)

{

const int monthLengths[2][13]={

{0,31,59,90,120,151,181,212,243,273,304,334,365 },

{0,31,60,91,121,152,182,213,244,274,305,335,366 }

};

const int yearLengths[2]={365,366};

int year(0),month(0),minMonth(0),maxMonth(0),days(0),clock(0),isLeap(0),day(0),hour(0),minute(0),second(0);

time/=1000;

time+=timezone*60*60;

days=time/86400;//天数

clock=time%86400;//小时数

if(clock0)

{

clock+=86400;

days-=1;

}

if(days=0)

{

year=days/366;

days-=year*365+(year+1)/4-(year+69)/100+(year+369)/400;

for (year=year+1970;;year++)

{

isLeap=IsLeap(year);

if(daysyearLengths[isLeap])

{

break;

}

days-=yearLengths[isLeap];

}

}

else

{

year=days/366;

days-=year*365+(year-2)/4-(year-30)/100+(year-30)/400;

for(year=year+1970-1;;year--)

{

isLeap=false;

days+=yearLengths[isLeap];

if (days=0)

{

break;

}

}

}

minMonth=0;

maxMonth=12;

for (month=5;month12&&month0;month=(minMonth+maxMonth)/2)

{

if (daysmonthLengths[isLeap][month])

{

maxMonth=month;

}

else if (days=monthLengths[isLeap][month+1])

{

minMonth=month;

}

else

{

break;

}

}

days-=monthLengths[isLeap][month];

month++;

day=days+1;

hour=clock/3600;

clock=clock%3600;

minute=clock/60;

second=clock%60;

CString t;

t.Format(TEXT(%d-%02d-%02d %02d:%02d:%02d),year,month,day,hour,minute,second);

return t;

}

取消

评论

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值