Created
May 5, 2017 15:13
-
-
Save seumasmorrison/eabcd7671da06be33015f544c9f12dc1 to your computer and use it in GitHub Desktop.
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, 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