// Convert Julian Day number to lilian,mjd,j1900(excel date),j1904(MAC excel),unix epoch time void cvtjdn(long jdn,long *lilian,long *mjd,long *j1900,long *j1904,unsigned long *utime) { // Update Excel 1900 and 1904 day serial numbers #define JLILIAN 2299160 //Epoch of Lilian date (days since 1582-10-15 #define JMJD 2400001 // Epoch of Modified Julian Date system #define J1900 2415021 // Epoch (day 1) of Excel 1900 date system (PC) #define J1904 2416481 // Epoch (day 0) of Excel 1904 date system (Mac) #define J1970 2440588 // Julian date at Unix epoch: 1970-01-01 // days since 1900 (MS Excel date) *j1900 = (jdn - J1900) + 1 ; /* Microsoft marching morons thought 1900 was a leap year. Adjust dates after 1900-02-28 to compensate for their idiocy. */ // *j1900 = (jdn - J1900) + 1+ ((jdn > 2415079) ? 1 : 0); //MAC Excel days since 1904 *j1904 = jdn - J1904; // lilian date *lilian = jdn - JLILIAN; // Modified julian Day *mjd = jdn - JMJD; // Update Unix time() *utime = 0; if (jdn >= J1970) *utime = (unsigned long)(jdn - J1970) * (unsigned long)(60 * 60 * 24); } #ifdef TEST #include #include int main(int argc, char *argv[]) { long jdn,lilian=0,mjd=0,j1900=0,j1904=0; unsigned long utime=0; if (argc < 2) jdn=JMJD; else jdn=atol(argv[1]); cvtjdn(jdn,&lilian,&mjd,&j1900,&j1904,&utime); printf("jdn %d lilian %d mjd %d j1900 %d j1904 %d utime %lu\n",jdn,lilian,mjd,j1900,j1904,utime); return 0; } #endif