In [28]:
from datetime import datetime
import time
from matplotlib.dates import date2num
In [39]:
datetime_object = datetime(2015, 8, 7)
date_str = datatime_object.strftime("%Y-%m-%d") # %Y-%m-%d %H:%M:%S
date_str # string type
Out[39]:
In [41]:
datetime(2015, 8, 7).strftime("%Y-%m-%d") # datetime(2015, 8, 7, 20,6,39)
Out[41]:
In [49]:
string = "2015-08-05"
datetime.strptime(string, "%Y-%m-%d")
Out[49]:
In [46]:
string = "2015-08-05 17:50:30"
datetime.strptime(string, "%Y-%m-%d %H:%M:%S")
Out[46]:
In [50]:
date2num(datetime.strptime("2015-08-05","%Y-%m-%d"))
Out[50]:
In [51]:
time.mktime(time.strptime("2015-08-05","%Y-%m-%d"))
Out[51]: