Created
September 17, 2023 11:24
-
-
Save EH30/39e85dba3da871215e91fae16bd6c8ea to your computer and use it in GitHub Desktop.
Python script to calculate juilan date
This file contains 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
from datetime import datetime | |
def date_utc_to_julian(year, month, day, hour, minute, second, utc_offset_hours, utc_offset_minutes): | |
# Convert the date to a datetime object | |
dt = datetime(year, month, day, hour, minute, second) | |
# Calculate the Julian date offset | |
julian_offset = 2440587.5 | |
# Calculate the number of seconds in a day | |
seconds_per_day = 86400 | |
# Convert the UTC offset to seconds | |
utc_offset_seconds = (utc_offset_hours * 3600) + (utc_offset_minutes * 60) | |
# Calculate the Julian date | |
julian_date = julian_offset + (dt - datetime(1970, 1, 1)).total_seconds() / seconds_per_day - utc_offset_seconds / seconds_per_day | |
return julian_date | |
if __name__ == "__main__": | |
year = 2009 | |
month = 3 | |
day = 30 | |
hour = 9 | |
minute = 36 | |
second = 0 | |
utc_hour = 5 | |
utc_minute = 30 | |
latitude = 19.0760 | |
longitude = 72.8777 | |
juld = date_utc_to_julian(year, month, day, hour, minute, second, utc_hour, utc_minute) | |
print(juld) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment