How to get the current time in Python

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

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

30条回答
  •  爱一瞬间的悲伤
    2020-11-22 07:16

    You can use the time module:

    import time
    print time.strftime("%d/%m/%Y")
    
    >>> 06/02/2015
    

    The use of the capital Y gives the full year, and using y would give 06/02/15.

    You could also use the following code to give a more lengthy time:

    time.strftime("%a, %d %b %Y %H:%M:%S")
    >>> 'Fri, 06 Feb 2015 17:45:09'
    

提交回复
热议问题