Skip to content

Instantly share code, notes, and snippets.

@shiumachi
Created November 29, 2018 01:58
Show Gist options
  • Save shiumachi/9bd702585ad590e720bf68ee036a0012 to your computer and use it in GitHub Desktop.
Save shiumachi/9bd702585ad590e720bf68ee036a0012 to your computer and use it in GitHub Desktop.
import datetime
def convert_to_datetime(date_string):
""" input: %Y-%m-%d %H:%M:%S,%f
example: 2014-01-05 22:20:50,307
return: datetime object
"""
date_format = "%Y-%m-%d %H:%M:%S,%f"
return datetime.datetime.strptime(date_string, date_format)
if __name__ == '__main__':
date_string = "2014-01-05 22:20:50,307"
print("date_string: {0}".format(date_string))
print("convert_to_datetime: {0}".format(convert_to_datetime(date_string)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment