How to get the current time in Python

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

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

30条回答
  •  攒了一身酷
    2020-11-22 07:39

    import datetime
    
    todays_date = datetime.date.today()
    print(todays_date)
    >>> 2019-10-12
    
    # adding strftime will remove the seconds
    current_time = datetime.datetime.now().strftime('%H:%M')
    print(current_time)
    >>> 23:38
    

提交回复
热议问题