我想将输入日期时间格式更改为输出日期时间格式: 输入日期时间格式 = 2021 年 4 月 5 日 06:46:16 GMT
然后我做到了:
input = input.replace(newdate[:5],"") #05 2021 年 4 月 06:46:16 格林威治标准时间
输出日期时间格式 05/04/2021 06:46:16
答案 0 :(得分:0)
import datetime
input_format = '05 Apr 2021 06:46:16 GMT'
input_list = input_format.split() #split the string and store in list
modified_input = " ".join(input_list[0:-1]) #removing the last element which is GMT and then joining all the strings in the list
output_format = datetime.datetime.strptime(modified_input, "%d %b %Y %H:%M:%S")
print(output_format.strftime("%d/%m/%Y %H:%M:%S"))