#include main() { long int time; int i,j,c,n,base_year; char sd[9],st[9],s[20]; printf(" Please enter the time in seconds: "); gets(s); time = atoi(s); printf(" Please enter the baseline year (default = 70): "); gets(s); if ( s[0] == '\0' ) base_year = 70; else { base_year = atoi(s); if (base_year > 1900) base_year = base_year - 1900; } date(sd,st,time,base_year); printf("\n %9s %9s\n",sd,st); } date (sd, st, itime, base_year) char sd[],st[]; long int itime; int base_year; { long int itime2; int mon,day,yr,tday,i,ndays=365,ind; int hr,min,sec; static int julian[2][12] = { {1,32,60,91,121,152,182,213,244,274,305,335}, {1,32,61,92,122,153,183,214,245,275,306,336}}; yr = base_year; itime2 = itime; while ((itime2 - ndays*86400) > 0) { yr = yr + 1; itime2 = itime2 - ndays*86400; if (yr%4 == 0) ndays = 366; else ndays = 365; } if (yr%4 == 0) ind = 1; else ind = 0; mon = 12; tday = itime2/86400; for (i=1; i<=12; i++) { if (julian[ind][i-1] > tday+1) { mon = i-1; break; } } day = tday - julian[ind][mon-1] + 2; itime2 = itime2 - (julian[ind][mon-1]+day-2)*86400; hr = itime2/3600; itime2 = itime2 - hr*3600; min = itime2/60; itime2 = itime2 - min*60; sec = itime2; sd[0] = '0' + (mon/10); sd[1] = '0' + (mon%10); sd[2] = '-'; sd[3] = '0' + (day/10); sd[4] = '0' + (day%10); sd[5] = '-'; sd[6] = '0' + (yr/10); sd[7] = '0' + (yr%10); sd[8] = '\0'; st[0] = '0' + (hr/10); st[1] = '0' + (hr%10); st[2] = ':'; st[3] = '0' + (min/10); st[4] = '0' + (min%10); st[5] = ':'; st[6] = '0' + (sec/10); st[7] = '0' + (sec%10); st[8] = '\0'; return(1); }