Created
December 23, 2012 21:38
-
-
Save conradlee/4366296 to your computer and use it in GitHub Desktop.
How to convert matlab's datenum representation of time to python's datetime representation.
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
from datetime import datetime, timedelta | |
matlab_datenum = 731965.04835648148 | |
python_datetime = datetime.fromordinal(int(matlab_datenum)) + timedelta(days=matlab_datenum%1) - timedelta(days = 366) |
Cross referencing the gist to its matching blog post: https://sociograph.blogspot.com/2011/04/how-to-avoid-gotcha-when-converting.html
I have tried the suggestion by conradlee and wjwxxn, but they both do not work for an array of precise ordinal times (e.g. times like 731965.04835648148 in an array).
daluu, the link you gave goes to a blog, which has a comment to come here, which was also a redirection from another post ... the solutions trail is circular, and nothing seems to be working with an array of ordinal times in decimals.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Maybe this is simpler:
python_datetime = datetime.timedelta(days=matlab_datenum -366)+datetime.datetime(1,1,1)