我正在尝试编写 C++ 代码来计算自 1970 年 1 月 1 日起的年数、月数、周数、小时数和分钟数。我包括我目前拥有的代码。请帮我。提前致谢。
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(){
double seconds, minutes, days, weeks, months, years, hours;
seconds = time(NULL);
minutes = seconds / 60;
hours = minutes / 60;
days = hours / 24;
weeks = days / 7;
months = weeks / 4;
years = days / 365;
months = (int) (days / 30.42) % 12;
weeks = (int) (days / 7) % 52;
days = (int) (hours / 24) % 24;
hours = (int) (minutes / 60) % 1;
minutes = (int) (seconds / 60) % 60;
printf("%d years \n", (int)years);
printf(" %d months \n", (int)months);
printf(" %d weeks\n", (int)weeks);
printf(" %d days \n", (int)days);
printf(" %d minutes\n", (int)minutes);
printf(" %d hours\n\n", (int)hours);
system("pause");
}