如何在Python中获取当前时间 [英] How to get the current time in Python
本文介绍了如何在Python中获取当前时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
用于获取当前时间的模块/方法是什么?
解决方案
使用:
>>导入日期时间
>> datetime.datetime.now()
datetime.datetime(2009、1、6、15、8、24、78915)
> print(datetime.datetime.now())
2009-01-06 15:08:24.789150
还有时间:
>> datetime.datetime.now()。time()
datetime.time(15、8、24、78915)
>> print(datetime.datetime.now()。time())
15:08:24.789150
有关更多信息,请参见 文档 。 / p>
要保存键入内容,可以从 datetime $ c导入
datetime
对象$ c>模块:
>>从datetime导入datetime
然后删除前导的 datetime。
以上所有。
What is the module/method used to get the current time?
解决方案
Use:
>>> import datetime
>>> datetime.datetime.now()
datetime.datetime(2009, 1, 6, 15, 8, 24, 78915)
>>> print(datetime.datetime.now())
2009-01-06 15:08:24.789150
And just the time:
>>> datetime.datetime.now().time()
datetime.time(15, 8, 24, 78915)
>>> print(datetime.datetime.now().time())
15:08:24.789150
See the documentation for more information.
To save typing, you can import the datetime
object from the datetime
module:
>>> from datetime import datetime
Then remove the leading datetime.
from all of the above.
这篇关于如何在Python中获取当前时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文