注册 登录
编程论坛 Python论坛

不能同时使用吗?

Z89 发布于 2023-07-09 09:15, 538 次点击
from datetime import datetime, date
import datetime
不能同时使用吗?


程序代码:



import time
from datetime import datetime, date
import datetime


localtime = time.localtime()
time_1 = time.strftime("%H:%M:%S", localtime)
time_2 = '09:05:00'

time_1_struct = datetime.strptime(time_1, "%H:%M:%S")
time_2_struct = datetime.strptime(time_2, "%H:%M:%S")
seconds = (time_2_struct - time_1_struct).seconds
print('等待:'+  str(seconds))
time.sleep(seconds)

d = datetime.datetime.now()
ca=(d+datetime.timedelta(days=8)).strftime('%#m/%#d')
dooy=  str(ca)   
print(dooy)
2 回复
#2
sheeboard2023-07-09 09:39
命名冲突,下面那个用import datetime as dt
#3
yiqiume2023-08-30 11:41
两个datetime的命名空间
1