python 获取当前时间和日期
import time
def get_now_time():
"""
获取当前日期时间
:return:当前日期时间
"""
now = time.localtime()
now_time = time.strftime("%Y-%m-%d %H:%M:%S", now)
# now_time = time.strftime("%Y-%m-%d ", now)
return now_time
if __name__ == '__main__':
now_time = get_now_time()
print(now_time)
2022-03-05 15:32:14