Convert MODIS day-of-year (julian date) to yyyymmdd date format using python

Published: 10 mars 2017

DMCA.com Protection Status

Simple exemple on how to convert MODIS day-of-year (also called julian date even if the definition of julian date is not exactly the same thing) to MM/DD/YYYY date format using python

import calendar

def JulianDate_to_MMDDYYY(y,jd):
    month = 1
    day = 0
    while jd - calendar.monthrange(y,month)[1] > 0 and month <= 12:
        jd = jd - calendar.monthrange(y,month)[1]
        month = month + 1
    print month,jd,y

JulianDate_to_MMDDYYY(2008,167)

Results:

6 15 2008

Checking the code (inverse operation):

from datetime import date

d0 = date(2008, 1, 1)
d1 = date(2008, 6, 15)
delta = d1 - d0
print delta.days+1

Result:

167

see Julian Day Calendar

Recherches associées