python打印当前时间,例如:
1.显示年-月-日-时-分-秒,
2.显示年-月-日
3.显示年-月-日-时-分-秒-ms
实现效果如图所示:
简易代码如下:
import time
if __name__ == "__main__":
# 打印格式化时间
print(time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())))
print(time.strftime('%Y-%m-%d',time.localtime(time.time())))
ms简易代码如下:
from datetime import datetime
print(datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3])
#2022-06-23 15:00:41.124
老是忘记又经常用得到,写下来就很必要哦!