now = datetime.now()
print(datetime.today())
print(now.year, now.month, now.day, now.hour, now.minute, now.second, now.microsecond)
print(now.strftime('%Y年%m月%d日%H时%M分%S秒%f毫秒'))
print(now.date(), '--', now.ctime())
获取当前时间并打印,结果如下图:
a = datetime.now()
time.sleep(10)
b = datetime.now()
c = b - a
print(c.total_seconds())
print('time cost:{}s {}ms'.format(c.seconds, c.microseconds))