数据类型及操作
Python 标准库的datetime
datetime模块中的datetime,time,calendar等类都可以用来存储时间类型以及一些其他转换与运算
for example:
from datetime import datetime
now=datetime.now()
print now
#2016-09-11 16:02:35.788000
delta=datetime(2010,2,2)-datetime(2010,2,1)
#2016-09-12 16:04:01.845000
ddatetime的对象见的减法运算会得到一个timedelta对象,表示一个时间段
datetime 对象与它所保存的字符格式时间戳之间可以相互转化,str()函数可用,更推荐datetime.strptime()。这2两个方法之间可以相互转换
str(now)
now.strftime('%Y-%m-%d')
print now.strftime('%Y-%m-%d %H:%M:%S %Z')
strptime and strptime ---------------------------
datetiem.strptime('2001-10-1','%Y-%m-%d') # can not be strftime
将格式为datetime 转换为 TimeStamp
pd.to_datetime(now)