
Python
以下是一个示例代码,可以输出当前时间的日期和时间:
Python
from datetime import datetime
now = datetime.now()
print("当前时间为:", now)
print("当前日期为:", now.date())
print("当前时间为:", now.time())
运行以上代码,输出结果如下:
当前时间为: 2022-02-22 14:36:31.262652
当前日期为: 2022-02-22
当前时间为: 14:36:31.262652
其中,now()函数返回一个包含当前日期和时间的datetime对象,date()函数可以获取当前日期,time()函数可以获取当前时间。
Copyright © 2025 IZhiDa.com All Rights Reserved.
知答 版权所有 粤ICP备2023042255号