time模块:提供各种函数来操作时间值 datetime模块:提供各种函数来操作日期值
时间转换过程
import time
import datetime
timeStamp1
=time
.time
()
print(timeStamp1
)
struct_time1
=time
.localtime
(timeStamp1
)
print(struct_time1
)
struct_time2
=time
.gmtime
(timeStamp1
)
print(struct_time2
)
print(time
.strftime
('%Y-%m-%d %H:%M:%S',struct_time1
))
now
='2020-10-07 19:16:48'
struct_time3
=time
.strptime
(now
,'%Y-%m-%d %H:%M:%S')
print(struct_time3
)
timeStamp2
=time
.mktime
(struct_time3
)
print(timeStamp2
)
now
=datetime
.datetime
.now
()
print(now
)
print(now
.strftime
('%Y-%m-%d %H:%M:%S'))
print(datetime
.date
.fromtimestamp
(time
.time
()))
threeDayAgo
=datetime
.datetime
.now
()-datetime
.timedelta
(days
=3)
print(threeDayAgo
)
转载请注明原文地址:https://blackberry.8miu.com/read-33695.html