求助:如何把时间转换成从1970.01.01 00:00:00开始的秒数?
先谢过各位了!情况是这样的,现有 年,天(某年的第几天),时,分,秒 怎么转换成从1970.01.01 00:00:00开始的秒?
谢谢了
程序代码:
root@~ #cat lx92.c
#include <stdio.h>
struct date {
int year;
int month;
int day;
int hour;
int minute;
int second;
};
int main (void) {
int getDaysOfDate (struct date d);
struct date theday;
struct date seventy={ 1970,01,01,0,0,0 };
int Days,totalsec=0;
printf ("Enter date [yyyy mm dd hh:mm:ss]:");
scanf ("%i %i %i %i:%i:%i",&theday.year,&theday.month,&theday.day,
&theday.hour,&theday.minute,&theday.second);
totalsec=theday.hour*3600+theday.minute*60+theday.second;
Days=getDaysOfDate(theday)-getDaysOfDate(seventy);
totalsec=totalsec+Days*24*3600;
printf ("%i%\n",totalsec);
return 0;
}
int getDaysOfDate (struct date d) {
int days;
if(d.month<=2) {
days=1461*(d.year-1)/4+153*(d.month+13)/5+d.day;
}else{
days=1461*d.year/4+153*(d.month+1)/5+d.day;
}
return days;
}
root@~ #
