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

版权声明:本文为weixin_44493841原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/weixin_44493841/article/details/107109384