How to get the current time in Python

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

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

30条回答
  •  南方客
    南方客 (楼主)
    2020-11-22 07:26

    By default, now() function returns output in the YYYY-MM-DD HH:MM:SS:MS format. Use the below sample script to get the current date and time in a Python script and print results on the screen. Create file getDateTime1.py with the below content.

    import datetime
    
    currentDT = datetime.datetime.now()
    print (str(currentDT))
    

    The output looks like below:

    2018-03-01 17:03:46.759624
    

提交回复
热议问题