时间模块:datetime 1.datetime.date:date对象 年月日
datetime.date.today() 该对象类型为datetime.date 可以通过str函数转化为str In [1]: import datetime
In [2]: today = datetime.date.today()
In [3]: today Out[3]: datetime.date(2020, 4, 28)
In [4]: print(today,type(today)) 2020-04-28 <class ‘datetime.date’>
In [5]: print(str(today)) 2020-04-28
2.datetime.datetime:datetime对象 年月日时分秒-
datetime.datetime.now() datetime.datetime.today() 对象类型为datetime.datetime 可以通过str函数转为str In [6]: now = datetime.datetime.now()
In [7]: now Out[7]: datetime.datetime(2020, 4, 28, 22, 48, 16, 780405)
In [8]: print(now,type(now)) 2020-04-28 22:48:16.780405 <class ‘datetime.datetime’>
In [9]: print(str(now),type(str(now))) 2020-04-28 22:48:16.780405 <class ‘str’> 创建datetime对象:datetime.datetime(x,x,x,x,x) 无时间默认0点 In
|