if[ $(( ${hour[2]}- $cf - ${hour[1]}))-lt 0 ]; then hourtime="$(( ${hour[2]} - $cf + 60 - ${hour[1]} ))" cf=1 else hourtime="$(( ${hour[2]} - $cf - ${hour[1]} ))" cf=0 fi #test info #echo "this is hour" #echo "$hourtime"
#day #this part need the function moudle "day" in the same directory with this script daytime=$(./day ${year[1]} ${month[1]} ${day[1]} ${year[2]} ${month[2]} $(( ${day[2]}- $cf ))) #test info #echo "this is day" #echo "$daytime" echo echo "the time during" echo "${year[1]}/${month[1]}/${day[1]} ${hour[1]}:${min[1]}:${sec[1]}:${msec[1]}" echo "and" echo "${year[2]}/${month[2]}/${day[2]} ${hour[2]}:${min[2]}:${sec[2]}:${msec[2]}" echo -n "is : " echo
天数计算day.c:
#include<stdio.h> #include<stdlib.h> #include<string.h> #ifndef __SDATE__ #define __SDATE__ struct SDate { shortint year; shortint month; shortint day; }; typedefstruct SDate Sdate; #endif int IsLeapYear(short year); int DaysOfOneYear(Sdate sd); int SDateToAbsDays(Sdate sd); int IsLeapYear(short year){ return year%4==0&&year%100||year%400==0; } int DaysOfOneYear(Sdate sd){ switch(sd.month-1){ case 11: sd.day+=30; case 10: sd.day+=31; case 9: sd.day+=30; case 8: sd.day+=31; case 7: sd.day+=31; case 6: sd.day+=30; case 5: sd.day+=31; case 4: sd.day+=30; case 3: sd.day+=31; case 2: sd.day+=IsLeapYear(sd.year)?29:28; case 1: sd.day+=31; } return sd.day; }
int SDateToAbsDays(Sdate sd){ int years = sd.year -1; int days = years*365 + years/4 - years/100 + years/400; days+=DaysOfOneYear(sd); return days; } int main(int argc,char*argv[]) { Sdate d1,d2; int day=0; argv[0]="day"; d1.year=atoi(argv[1]); d1.month=atoi(argv[2]); d1.day=atoi(argv[3]); d2.year=atoi(argv[4]); d2.month=atoi(argv[5]); d2.day=atoi(argv[6]); day=SDateToAbsDays(d2)-SDateToAbsDays(d1);