How to get the current time in Python

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

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

30条回答
  •  悲&欢浪女
    2020-11-22 07:24

    This is what I ended up going with:

    >>>from time import strftime
    >>>strftime("%m/%d/%Y %H:%M")
    01/09/2015 13:11
    

    Also, this table is a necessary reference for choosing the appropriate format codes to get the date formatted just the way you want it (from Python "datetime" documentation here).

    strftime format code table

提交回复
热议问题