Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seumasmorrison/eabcd7671da06be33015f544c9f12dc1 to your computer and use it in GitHub Desktop.
Save seumasmorrison/eabcd7671da06be33015f544c9f12dc1 to your computer and use it in GitHub Desktop.
from datetime import datetime, timedelta
def from_matlab_datetime(matlab_datenum):
return datetime.fromordinal(int(matlab_datenum)) + timedelta(days=matlab_datenum%1) - timedelta(days = 366)
def datetime2matlabdn(dt):
mdn = dt + timedelta(days = 366)
frac_seconds = (dt-datetime(dt.year,dt.month,dt.day,0,0,0)).seconds / (24.0 * 60.0 * 60.0)
frac_microseconds = dt.microsecond / (24.0 * 60.0 * 60.0 * 1000000.0)
return mdn.toordinal() + frac_seconds + frac_microseconds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment