将 timett = "30/07/2019 11:26:35" 转换成自己想要的格式如 timenn = "30/07/2019 11:26"
# -*- encoding=utf8 -*-
import time
timtt="30/07/2019 11:26:35"
time1 = time.strptime(timtt, '%d/%m/%Y %H:%M:%S') # 函数根据指定的格式把一个时间字符串解析为时间元组。
time2 = time.strftime('%d/%m/%Y %H:%M', time1) #函数接收以时间元组,并返回以可读字符串表示的当地时间,格式由参数格式决定
time3 = time.strftime('%Y/%m/%d %H:%M', time1)
time4 = time.strftime('%Y-%m-%d %H:%M', time1)
print(time1, type(time1))
print(time2, type(time2))
print(time3, type(time3))
print(time4, type(time4))
输入结果是:
time.struct_time(tm_year=2019, tm_mon=7, tm_mday=30, tm_hour=11, tm_min=26, tm_sec=35, tm_wday=1, tm_yday=211, tm_isdst=-1)
30/07/2019 11:26
2019/07/30 11:26
2019-07-30 11:26