Python 时间戳 时间元组 日期 相互转换


# date == > ts format = "%Y-%m-%d %H:%M:%S" new_format = "%Y %m %d %H-%M-%S" date = '2022-04-20 15:59:00' struct_time = time.strptime(date, format) ts = time.mktime(struct_time) print(ts) # ts ==> date ts = time.time() st = time.localtime(ts) date = time.strftime(format,st) print(date) # date ==> new_date st = time.strptime(date,format) new_date = time.strftime(new_format,st) print(new_date)
浙公网安备 33010602011771号