Python 日期格式
Python Date-Format
我想将输入日期时间格式更改为输出日期时间格式:
输入日期时间格式 = 2021 年 4 月 5 日 06:46:16 GMT
然后我做了:
输入 = input.replace(新日期[:5],"")
#2021 年 4 月 5 日 06:46:16 格林威治标准时间
输出日期时间格式 05/04/2021 06:46:16
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"))
我想将输入日期时间格式更改为输出日期时间格式: 输入日期时间格式 = 2021 年 4 月 5 日 06:46:16 GMT
然后我做了:
输入 = input.replace(新日期[:5],"") #2021 年 4 月 5 日 06:46:16 格林威治标准时间
输出日期时间格式 05/04/2021 06:46:16
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"))