python显示当前时间

from datetime import datetime
from dateutil.parser import parse
import pandas as pd

#查看当前时间
now  = datetime.now()
print(now.year,now.month,now.day)#当前时间
#时间差
delta = datetime(2020,1,1)-datetime(2010,1,1)
print(delta)
#字符串与时间互换
stamp = datetime(2011,1,2)
print(type(str(stamp)))
print(stamp.strftime('%Y-%m-%d'))

value='2011-01-03'
da = datetime.strptime(value,'%Y-%m-%d')
print(da)
#换一种方法显示日期
m=parse('2011-3-20')
print(m)
m=parse('6/12/2011',dayfirst=True)
print(m)
datastrs = ['2011-3-20','2011-5-20']
print(pd.to_datetime(datastrs))

你可能感兴趣的:(python,机器学习,python)