python:将时间戳格式化为yyyyMMdd hh:mm:ss

 

import time

#将10位时间戳或者13位转换为时间字符串,默认为2017-10-01 13:37:04格式
def timestamp_to_date(time_stamp, format_string="%Y-%m-%d %H:%M:%S"):
    time_array = time.localtime(time_stamp/1000)
    other_style_time = time.strftime(format_string, time_array)
    print other_style_time
    return other_style_time
timestamp_to_date(1593693029909)

输出

2020-07-02 20:30:29

 

posted @ 2019-11-14 10:54  秋寻草  阅读(5035)  评论(0编辑  收藏  举报