我最近开始使用此教程学习python,并希望在我的python脚本中打印当前时间。我做了很多研究**,但是找不到关于**获取和打印python中当前时间的问题的答案。
这是我当前的Python脚本代码
def printTime():
print("The time is"+time+"right now");
printTime();
我想要这样
只需使用模块的datetime.now()
方法datetime
:-
import datetime
time=datetime.datetime.now()
def printTime():
print("The time is",time,"right now");
printTime()
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句