How to get the current time in Python

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

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

30条回答
  •  不知归路
    2020-11-22 07:23

    import datetime
    date_time = datetime.datetime.now()
    
    date = date_time.date()  # Gives the date
    time = date_time.time()  # Gives the time
    
    print date.year, date.month, date.day
    print time.hour, time.minute, time.second, time.microsecond
    

    Do dir(date) or any variables including the package. You can get all the attributes and methods associated with the variable.

提交回复
热议问题