根据Unix时间戳计算时间,不分大小月,每月30天,每年按360天计算。开始时间1970/01/01 00:00:00,输入秒数,显示时间
输入:10
返回:1970/01/01 00:00:10
输入:12345678
返回:1970/05/23 21:21:18
string CalculationDate(long long second)
{
int year = 1970,month = 1,day = 1;
int hour = 0,minute = 0;
while(second > 60)
{
second -= 60;
minute += 1;
if (minute == 60)
{
minute = 0;
hour += 1;
if (hour == 24)
{
hour = 0;
day += 1;
if (day == 31)
{
day = 1;
month += 1;
if (month == 13)
{
month = 1;
year += 1;
}
}
}
}
}
char buff[] = "1970/01/01 00:00:10";
sprintf(buff,"%d/%02d/%02d %02d:%02d:%02d",year,month,day,hour,minute,second);
return buff;
}
void Test()
{
cout<<CalculationDate(10)<<endl;
cout<<CalculationDate(12345678)<<endl;
}
int main()
{
Test();
system("pause");
return 0;
}