详见:https://www.runoob.com/python3/python3-date-time.html
    获取当前时间的两种方法:

    1. #方法1
    2. import time
    3. current_time = time.strftime("%Y-%m-%d, %H:%M:%S",time.localtime())
    4. print(current_time)
    1. #方法2
    2. from datetime import datetime
    3. current_time = datetime.now().strftime("%Y-%m-%d, %H:%M:%S")
    4. print(current_time)

    一个小小的时钟:

    1. import time
    2. while True:
    3. current_time = time.strftime("%H:%M:%S",time.localtime()) # 用了方法1
    4. sys.stdout.write(current_time + '\r')
    5. sys.stdout.flush()
    6. time.sleep(1)

    定时任务:

    1. settime='03:00' # 订个好时间叫孙子起床
    2. while True:
    3. current_time = time.strftime("%H:%M:%S",time.localtime())
    4. if current_time[:5] == settime:
    5. print('起床了')
    6. break