How to get the current time in Python

前端 未结 30 1957
滥情空心
滥情空心 2020-11-22 06:47

What is the module/method used to get the current time?

30条回答
  •  南方客
    南方客 (楼主)
    2020-11-22 07:20

    The previous answers are all good suggestions, but I find it easiest to use ctime():

    In [2]: from time import ctime
    In [3]: ctime()
    Out[3]: 'Thu Oct 31 11:40:53 2013'
    

    This gives a nicely formatted string representation of the current local time.

提交回复
热议问题