How to get the current time in Python

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

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

30条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-22 07:38

    Using pandas to get the current time, kind of overkilling the problem at hand:

    import pandas as pd
    print(pd.datetime.now())
    print(pd.datetime.now().date())
    print(pd.datetime.now().year)
    print(pd.datetime.now().month)
    print(pd.datetime.now().day)
    print(pd.datetime.now().hour)
    print(pd.datetime.now().minute)
    print(pd.datetime.now().second)
    print(pd.datetime.now().microsecond)
    

    Output:

    2017-09-22 12:44:56.092642
    2017-09-22
    2017
    9
    22
    12
    44
    56
    92693
    

提交回复
热议问题