Created
July 29, 2014 15:08
-
-
Save huskercane/b9ca940f3735b9d30e3b to your computer and use it in GitHub Desktop.
Convert from java timestamp to python datetime and vice versa
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
def _convert_java_millis(java_time_millis): | |
"""Provided a java timestamp convert it into python date time object""" | |
ds = datetime.datetime.fromtimestamp( | |
int(str(java_time_millis)[:10])) if java_time_millis else None | |
ds = ds.replace(hour=ds.hour,minute=ds.minute,second=ds.second,microsecond=int(str(java_time_millis)[10:]) * 1000) | |
return ds | |
def _convert_datetime_java_millis(st): | |
"""Provided a python datetime object convert it into java millis""" | |
return long(time.mktime(st.timetuple()) * 1e3 + st.microsecond/1e3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment