def trans_format(time_string, from_format, to_format='%Y.%m.%d %H:%M:%S'): """ @note 时间格式转化 :param time_string: :param from_format: :param to_format: :return: """ time_struct = time.strptime(time_string,from_format) times = time.strftime(to_format, time_struct) return times
if __name__ == "__main__": cst_time="Tue Nov 06 00:00:00 CST 2018" format_time=trans_format(cst_time,'%a %b %d %H:%M:%S CST %Y', '%Y-%m-%d %H:%M:%S') print format_time
输出结果:
2018-11-06 00:00:00