-
-
Save ekapujiw2002/c0fd0888e648c6630bfe5de9235fb547 to your computer and use it in GitHub Desktop.
Convert to/from Julian date numbers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int julian(int y, int m, int d) { | |
return 367*y - | |
(7 * (y + (m+9)/12))/4 - | |
(3 * ((y + (m-9)/7)/100 + 1))/4 + | |
275*m/9 + d + 1721029; | |
} | |
void gregorian(int j, int *year, int *month, int *day) { | |
int a = j + 68569; | |
int b = 4*a / 146097; | |
int c = a - (146097*b + 3) / 4; | |
int d = 4000*(c+1) / 1461001; | |
int e = c - 1461*d/4 + 31; | |
int f = 80*e / 2447; | |
int g = f/11; | |
int h = e - 2447*f/80; | |
int m = f + 2 - 12*g; | |
int y = 100 * (b-49) + d + g; | |
*year = y; *month = m; *day = h; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment